ASP.NET interview questions: - Can you explain master pages concept in ASP.NET and how do you create master pages?
Master pages are templates which can be applied to your web pages to bring in consistent look and feel and uniform structure. By creating templates we also avoid lot of duplication of code across web pages.
For example let’s say you want all your web pages in your application to have left menu, banner and footer (Refer figure Master page concept). So you can create a template and then apply that template to your webpages.
Creating Master Pages: -
To create a master page you can use the “master page” template from visual studio as shown in the below figure. In order to apply the master template we can use “Web form using master page” template.
In the master page you can define place holder using “ContentPlaceHolder” control. This is the place where your ASP.NET pages will be plug in their data.
Once master page template is created with necessary place holders you can then later in the web pages use the “MasterPageFile” to refer the template and you can use the content place holder to plug data.
For instance you can see the below code snippet of a page which uses master pages. You can also see how the “ContentPlaceHolder1” is used to place a simple text data “Company was established in 1990”.
Also see the following ASP.NET interview questions video on ASP.NET Masterpages: -