Master Pages in ASP.Net 2.0
(Page 1 of 4 )
ASP.Net has provided us with powerful mechanisms to separate code and functionality from design and the user interface, by such concepts as web controls and code-behind. With ASP.Net 2.0, Microsoft has taken it up a notch, allowing us to completely separate the templates of the entire site from any code in individual pages, through a new concept called Master Pages.
Introduction
Generally speaking, web programmers are not designers. Not by a long shot. That’s the reason we love programmable web controls. We can insert them on the page, do all the programming around them in the code behind, and let the designer worry about how it all looks (without messing up our code!). It’s also why tools such as DreamWeaver are so popular. We can design templates, create pages based on those templates, modify only certain pieces of the page, and let DreamWeaver handle any updates to pages for which the template has been modified.
With old-school ASP, we used include files, and we used them nefariously. Every single navigation element and widget and snippet got thrown into an ASP page, and we would toss in our include statements all over the place, making it sometimes incredibly fun to find a programming error, or even a twice declared variable.
Then with ASP.Net 1.1, we had something of a mind-shift to object-oriented programming. Here we were able to plug in other server controls, HTML, and programmatic code, and encapsulate them all into one "user control." We could then plug that user control onto any number of pages in our application, and use that functionality all over the site. Of course, then you ran into somewhat serious issues when you needed to modify a user control. If you made any changes to the properties, methods, or events in a single user control, you would need to recompile all pages that used that control, as well as redeploy the entire assembly. And then the first visitor to the page gets the unwelcome surprise of waiting for the .Net runtime to recreate it.
So to not only address these issues, but also give the advantage of being able to template your entire site with one page, Microsoft has come up with Master Pages.
Next: Master Pages – The Concept >>
More ASP.NET Articles
More By Justin Cook