Today I would like to write about master pages in Asp.net in these we are placed how to add master page to the solution explorer and how to add child pages to solution explorer with examples.
Master Pages in Asp.net
- Whenever we want to have common header and common footer with in multiple pages of a web site then we can go for a Master Page implementation.
- For example Let us assume we are developing a website with 10 pages, All the web pages are having same header and same footer instead of designing same header and same footer with in 10 pages, We will design a master page with the common header and common footer once then the master page we can consume that by that 10 pages which are called as child pages.
- To develop a master page we have a predefined template called master page.
How To Add Master Page To The Solution Explorer
Step 1: Open solution explorer
Step 2: Select application name, Right click add new item
It will open add new item window
Here we are select a predefined template called Master page
click add button with this process one master page will be added to the solution explorer window
ASP.Net extension of the master page will be master. Every page will be .Master
Every master page mainly representing with 2 files
1. .Master
2. .Master.cs
1. .Master:
This file will support two modes
a) Design Mode
b) Source Mode
Structure of the Master Page source window(.master)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body style="height: 182px">
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
2. Master.cs:
It will contain the business logic of the master page
Structure of the Master Page Class File(.master.cs)
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
How To Add Child Page To The Solution Explorer
Step 1: Open solution explorer
Step 2: Select web application name right click select add new item
It will open a add new item window
Here select a template called web form click add button
Step 3: Here check the below check box like
Select master page
Click add button
It will open a window like select a master page. Here select a file MasterPage.master
Click ok button
With the above process MasterPage will be add to a child page called webform1.aspx
as well as a child page called webform1.aspx will added to solution explorer window
Structure of the Child Page .aspx code window
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Structure of the Child Page .aspx.cs
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Are you looking for more articles on .net I wrote More Articles on C#.Net and Asp.Net i think those also helpful to you.
0 comments:
Post a Comment