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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT