ASP.NET
  Home arrow ASP.NET arrow Page 4 - 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 - Going Beyond the Basics


    (Page 4 of 4 )

    There are many additional options we have with Master Pages, and I’ll highlight a few of what I believe to be the more useful ones.

    Site-wide Definition

    Something I could see becoming a pain is having to remember to reference the Master Page for every single content page in your site, especially if your application has many pages. Well of course the thoughtful ASP.Net team planned ahead to circumvent this issue, by allowing us to define a default Master Page for the entire application in the web.config file. To create this definition, you would place the following in the web.config file:

    <configuration>
          <system.web>
                <pages masterpagefile=”site.master” />
          </system.web>
    </configuration>

    Client-side Scripting

    This is more of a caveat than anything. Quite often we developers will implement some custom client-side JavaScript to manipulate the contents of our controls without having to perform a post back to the server. A good example of this would be a timesheet, for which you create JavaScript code that changes totals in real time as you enter your hours, and then checks and saves the values once you’re done and hit submit.

    When not using Master Pages, it’s quite simple to do this, because all of your web controls have an id parameter, and that id is transmitted when the HTML control is created. Therefore all you need to do is reference the ID of the object in JavaScript as you would in any HTML page.

    When I created my first Master/Content pages, I was annoyed to see that all of my client-side script "broke." As soon as I checked the generated source code, it was easy to see why. Every control id had been changed. Each still contained the original id, but now they had appended to the beginning a string something like the following: “_ctrl105_”.

    To fix any broken JavaScript references, what you’ll need to do is examine your browser’s source code, find what the appended string is in your case, and tell your JavaScript code to add it to the beginning of any object references it’s using.

    Customized Master Pages

    While the major browser creators still struggle to come to terms with complete standards compliance, there remains the possibility that we as developers may need to customize the UI somewhat to meet any inconsistencies. Coincidentally, the Microsoft team has allowed us to create different Master Pages for different browsers. You can form your own conclusions about the reasons why, I’m only here to show you how to do it!

    So we could take our standard Master Page reference:

    <%@ Page masterpagefile=”site.master” %>

    And we could tweak it to provide a Firefox friendly alternative:

    <%@ Page netscape:masterpagefile=”nsSite.master” masterpagefile=”site.master” %>

    And then even further to customize for Internet Explorer as well:

    <%@ Page netscape:masterpagefile=”nsSite.master”
    ie:masterpagefile=”ieSite.master” masterpagefile=”site.master” %>

    While you as a developer and a believer in web standards may grimace at the idea of creating separate templates for separate browsers, this is a still a good example of how flexible Master Pages are, even in their first revision!

    Conclusion

    Master Pages in my opinion will be enormously popular, among developers and designers alike. Another forward stride in the world of Rapid Application Development, I really have to hand it to the ASP.Net team on this one! I hope that with the assistance of this article, you will find them enjoyable to use, flexible, and simple to work with.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 2 hosted by Hostway
    Stay green...Green IT