ASP.NET
  Home arrow ASP.NET arrow Page 3 - Master Pages in ASP.Net 2.0
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Master Pages in ASP.Net 2.0
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2005-09-15

    Table of Contents:
  • Master Pages in ASP.Net 2.0
  • Master Pages – The Concept
  • Content Pages
  • Going Beyond the Basics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Master Pages in ASP.Net 2.0 - Content Pages


    (Page 3 of 4 )

    To define and populate a content page, the process is equally as painless. In the @Page directive, you simply need to indicate which Master Page the content page uses. Then with the page, you implement any controls (content) by placing them inside a "content" control, and indicate which content placeholder you’re filling. So the content page could be as simple as the following:

    <%@ Page Language=”C#” masterpagefile=”site.master” %>
    <asp:content runat=”server” contentplaceholderID=”bodyContents”>
          <p>this is some content to replace the default content</p>
    </asp:content>

    So you could save this as default.aspx, run the application, and the result would be a merge of the master and content pages, with the logo and the new paragraph attached.

    Something you may have noticed is that on default.aspx, I didn’t include the necessary <form runat=”server”> control. This may seem strange to you, but I assure you it’s not an error. The reason for this is that the form control is already implemented in the Master Page, and the result of the merging is that the content page inherits the form from its parent Master Page. It makes sense when you think about it!

    But the whole point of ASP.Net is not to put up static content on the web, but to create dynamic pages. So how would you do that in a content page? Well, the programmatic code still exists outside of the layout, and your code will take the following form:

    <%@ Page Language=”C#” masterpagefile=”site.master” %>
    <script runat=”server”>
          void calcClicks(object sender, EventArgs e)
          {
                int count = int.Parse(clickedLbl.Text)
                clickedLbl.Text = count++;
          }
    </script>
    <asp:content runat=”server” contentplaceholderID=”bodyContents”>
          <p>this is some content to replace the default content</p>
          <asp:button runat=”server” id=”clickBtn” text=”click”
                Onclick=”calcClicks” /><br />
          This button has been clicked
          <asp:label id=”clickedLbl” runat=”server”>0</asp:label>
          times.
    </asp:content>

    So we’ve thrown in some fairly simplistic code to count how many times a button has been clicked. Not brain surgery, but at least you can see how in-page coding will work. And there is no change to the code-behind page, so if you’re accustomed to working with that, you have nothing to learn anew!

    More ASP.NET Articles
    More By Justin Cook


       · Hi Everyone,just a quick note from the author here: hope you enjoy the article,...
     

    ASP.NET ARTICLES

    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT