In: Computer Science
Explain in your own words what is meant by the .NET term of "master pages"? Include an example.
A master page is an ASP.NET file with the extension . master (for example, MySiteABC. master) with a predefined layout that can include static text, HTML elements, and server controls. The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary.
Master pages provide templates for other pages on your web site.
Master pages allow you to create a consistent look and behavior for all the pages (or group of pages) in your web application.
A master page provides a template for other pages, with shared layout and functionality. The master page defines placeholders for the content, which can be overridden by content pages. The output result is a combination of the master page and the content page.
The content pages contain the content you want to display.
When users request the content page, ASP.NET merges the pages to produce output that combines the layout of the master page with the content of the content page.
When a web request arrives for an ASP.NET web form using a master page, the content page (.aspx) and master page (.master) merge their content together to produce a single page. Let’s say we are using the following, simple master page.
<%@MasterLanguage="VB" %>
<htmlxmlns="localhost/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ContentPlaceHolderID="ContentPlaceHolder1"runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
The master page contains some common elements, like a head tag. The most important server-side controls are the form tag (form1) and the ContentPlaceHolder (ContentPlaceHolder1). Let’s also write a simple web form to use our master page.
<%@PageLanguage="C#"MasterPageFile="~/Master1.master"
AutoEventWireup="true"Title="Untitled
Page" %>
<asp:ContentID="Content1"Runat="Server"
ContentPlaceHolderID="ContentPlaceHolder1">
<asp:LabelID="Label1"runat="server"Text="Hello,
World"/>
</asp:Content>
Please vote if you find this solution helpful.
Thank you.