What are Master Pages in .NET? Why we need Master Pages and how do we use Master Pages in our applications?
Life before Master Pages
For a given website, there are multiple web pages with common layout.
How we can achieve this?
- Write the layout of the code in each page. But this leads to code
redundancy which is not correct.
- We can achieve the common layout, by using User controls.
Advantage of User Controls:
- Turning an existing ASP.NET page into a user control requires only a few
minor changes. User controls can be easily linked to any page that needs their
services.
- Furthermore, changes to a user control's implementation do not affect
the referencing page and only require recompiling of the user control into an
assembly.
Disadvantage of User Controls:
- Any alteration to the control's public interface (such as the class
name, properties, methods, or events) leads to the pages that reference the
control must be updated.
- Those pages must be re-compiled and needs deployment.
- In addition, the next time a user views each page, the ASP.NET runtime
will take a while to respond because the dynamic assembly for the page must be
re-created.
Apart from the above two options, the other options is to use Master
pages. A Master page is a file that contains the static layout of the file. It
consists of the layout that is common throughout application (i.e. Application
Level) or a folder level and dynamic parts will be customized by the pages that
are derived from the Master page.
(Continued...) View Full Aritlce
|