Add a master page in your solution explorer and named it as "MasterPage.master"
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Red; color: White; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page1
</td>
<td style="background-color: Aqua; color: Black; height: 70px" align="center">
<asp:LinkButton ID="LinkButton1" ForeColor="Black" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" ForeColor="Black" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
Add one more master page in your solution explorer and named it as "MasterPage2.master"
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Lime; color: Black; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page2
</td>
<td style="background-color: Red; color: White; height: 70px" align="center">
<asp:LinkButton ForeColor="White" ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ForeColor="White" ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
Paste the following code in MasterPage.master.cs and MasterPage2.master.cs files
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=First");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=Second");
}
Add a new Web Form and named it as "Default.aspx" and set its default master page,that is "MasterPage.master"
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Paste the following code in _Default class in Default.aspx.cs file
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"].ToString())
{
case "First":
Page.MasterPageFile = "MasterPage.master";
break;
case "Second":
Page.MasterPageFile = "MasterPage2.master";
break;
}
}
}
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Red; color: White; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page1
</td>
<td style="background-color: Aqua; color: Black; height: 70px" align="center">
<asp:LinkButton ID="LinkButton1" ForeColor="Black" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" ForeColor="Black" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
Add one more master page in your solution explorer and named it as "MasterPage2.master"
Paste the following code in between div tag
<div><table width="100%">
<tr>
<td style="background-color: Lime; color: Black; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page2
</td>
<td style="background-color: Red; color: White; height: 70px" align="center">
<asp:LinkButton ForeColor="White" ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ForeColor="White" ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
Paste the following code in MasterPage.master.cs and MasterPage2.master.cs files
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=First");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=Second");
}
Add a new Web Form and named it as "Default.aspx" and set its default master page,that is "MasterPage.master"
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Paste the following code in _Default class in Default.aspx.cs file
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"].ToString())
{
case "First":
Page.MasterPageFile = "MasterPage.master";
break;
case "Second":
Page.MasterPageFile = "MasterPage2.master";
break;
}
}
}
No comments:
Post a Comment