In this article, we can see a simple solution for the master page coding . In future, update to framework 2 will be simple, since the solution is very similar to the new framework design.
Using the code
All we need to do for the master-page to work is:
- Derive our page from the master page.
- Enclose all the page in a tag named "
- Leave the form name "
Form1", as it come by default.
- Use a user control as the master, and include in its HTML code asp:placeholder named "
How does it work?
The master user control, has a tree of controls, one of them is the placeholder named "
ContentPlaceHolder". On the other hand, the page itself has a tree of controls, one of them is the "
content" (actually it has a tree under the list:
The process is:
- Take the content, and move it under the placeholder in the master user control.
- Take the hole master user control and move it to under the Form.
That is all.
The Master Page code:
public class MasterPage : System.Web.UI.Page
public MasterPage() : base()
this.Init +=new EventHandler(MasterPage_PreInit);
private void MasterPage_PreInit(object sender, EventArgs e)
UserControl template =
Control content = this.FindControl("content");
Here is a Master User Control. The only thing we must do is to include the placeholder named
Inherits= "MasterPage.MasterTemplate" ... %>
<TABLE id="Table1" runat="server">
<TD height="22" align="center">This Is The Header</TD>
<TD vAlign="top" align="right">
<tr height= "10>
Runat= "server">Fatal error...</asp:label>
<td align="center">This Is The Bottom</td>
And here is the page. All the code rendered in the
BODY must be enclosed in a tag named
<%@ Page ... %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<form id="Form1" method="post" runat="server">
<asp:panel id="content" runat="server" HorizontalAlign="Center">
<asp:Calendar id="Calendar1" runat="server" ... ></asp:Calendar>
And here is the page code behind. The only thing we must do is to derive it from the base page,
public class WebForm1 : MasterPage
Move to ASP.NET 2
To change our code to run under the new framework we will need to:
Or add in the page directive:
<%@ Page MasterPageFile="~/MasterPage.master" ... %>
The new view of Master Page in ASP.NET 2:
Other articles obout master page:
The code in this article is based on a presentation of Alik Levin from Microsoft.
Visit Yitzhak Gootvilig's blog.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.