Frequently Asked Interview Questions
Showing posts with label Master Pages. Show all posts
Showing posts with label Master Pages. Show all posts

Difference btn master page and user control in asp.net

Difference btn master page and user control in asp.net:

User control
1)A User control is an ASP.NET file with the extension .ascx
2)A page can have more than one User Controls.
3)it doesn't contain Contentplaceholder.

MasterPage:
1) A master page is an ASP.NET file with the extension .master
2)it used like a template.
3)it contain ContentPlaceHolder.
4)Only one master page can be assigned to a web page

Different ways to attach content pages to a master page

You can attach content pages to a master page at three levels:

1. page level

<%@ Page Language="C#" MasterPageFile="MySite.Master" %>


2. Application Level: By making a setting in the pages element of the application's configuration file

<pages masterPageFile="MySite.Master" />


3. At the folder level : This strategy is like binding at the application level, except that you make the setting in a Web.config file in one folder only

Run-time Behavior of Master Pages

At run time, master pages are handled in the following sequence:


  • Users request a page by typing the URL of the content page.
  • When the page is fetched, the @ Page directive is read. If the directive references a master page, the master page is read as well. If this is the first time the pages have been requested, both pages are compiled.
  • The master page with the updated content is merged into the control tree of the content page.
  • The content of individual Content controls is merged into the corresponding ContentPlaceHolder control in the master page.
  • The resulting merged page is rendered to the browser.
The process is illustrated in the following diagram.
Master pages at run time

Advantages of Master Pages in ASP.NET

Advantages of using Master Pages:

    Master pages defines a common template for all content pages. Below are the advantages of using master pages.
  • They allow you to centralize the common functionality of your pages so that you can make updates in just one place.
  • They make it easy to create one set of controls and code and apply the results to a set of pages. For example, you can use controls on the master page to create a menu that applies to all pages.
  • They give you fine-grained control over the layout of the final page by allowing you to control how the placeholder controls are rendered.
  • They provide an object model that allows you to customize the master page from individual content pages


Master Pages in ASP.NET

MasterPage: master pages allow you to create a consistent layout for the pages in your application.

A master page is an ASP.NET file with the extension .master.The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages. The directive looks like the following.

<%@ Master Language="C#" %>

Content Pages: You define the content for the master page's placeholder controls by creating individual content pages, which are ASP.NET pages (.aspx files and, optionally, code-behind files) that are bound to a specific master page. The binding is established in the content page's @ Page directive by including a MasterPageFile attribute that points to the master page to be used.

<%@ Page Language="C#" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page"%>

Most Visited Pages

Home | Site Index | Contact Us