Hi smile,
Refer below code,
HTML - Default Page
<table>
<tr>
<td>Username</td>
<td>
<asp:TextBox runat="server" ID="txtUserName" Text="User3" />
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox runat="server" ID="txtPassword" Text="abc@123" TextMode="Password" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button Text="Login" runat="server" OnClick="OnLogin" />
</td>
</tr>
</table>
<hr />
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="main_menu" />
<asp:MenuItemStyle CssClass="level_menu" />
</LevelMenuItemStyles>
<StaticSelectedStyle CssClass="selected" />
</asp:Menu>
MasterPage A,B,C,D,E,F,G
<html>
<head runat="server">
<title></title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
</style>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Module Page A
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_A.master" AutoEventWireup="true" CodeFile="Module_A.aspx.cs" Inherits="Model_A" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module A with master page A
</asp:Content>
Module Page B
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_B.master" AutoEventWireup="true" CodeFile="Module_B.aspx.cs" Inherits="Module_B" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module B with master page B
</asp:Content>
Module Page C
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_C.master" AutoEventWireup="true" CodeFile="Module_C.aspx.cs" Inherits="Module_C" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module C with master page C
</asp:Content>
Module Page D
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_D.master" AutoEventWireup="true" CodeFile="Module_D.aspx.cs" Inherits="Module_D" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module D with master page D
</asp:Content>
Module Page E
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_E.master" AutoEventWireup="true" CodeFile="Module_E.aspx.cs" Inherits="Module_E" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
Module E with master page E
</asp:Content>
Module Page F
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_F.master" AutoEventWireup="true" CodeFile="Module_F.aspx.cs" Inherits="Module_F" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module F with master page F
</asp:Content>
Module Page G
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage_G.master" AutoEventWireup="true" CodeFile="Module_G.aspx.cs" Inherits="Module_G" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Module G with master page G
</asp:Content>
C#
protected void OnLogin(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("UserID"),
new DataColumn("UserName"),
new DataColumn("UserPass"),
new DataColumn("ModuleA"),
new DataColumn("ModuleB"),
new DataColumn("ModuleC"),
new DataColumn("ModuleD"),
new DataColumn("ModuleE"),
new DataColumn("ModuleF"),
new DataColumn("ModuleG")
});
dt.Rows.Add(1, "User1", "abc@123", true, false, false, true, false, false, true);
dt.Rows.Add(2, "User2", "abc@123", false, true, true, false, true, false, false);
dt.Rows.Add(3, "User3", "abc@123", true, true, true, true, true, true, true);
DataRow dr = dt.AsEnumerable()
.Where(x => x["UserName"].ToString() == txtUserName.Text && x["UserPass"].ToString() == txtPassword.Text).FirstOrDefault();
Menu1.Items.Clear();
for (int i = 3; i < dr.ItemArray.Length; i++)
{
if (Convert.ToBoolean(dr.ItemArray[i].ToString()))
{
string menuName = string.Empty;
string menuURL = string.Empty;
switch (dt.Columns[i].ColumnName)
{
case "ModuleA":
menuName = "Module A";
menuURL = "~/Module_A.aspx";
break;
case "ModuleB":
menuName = "Module B";
menuURL = "~/Module_B.aspx";
break;
case "ModuleC":
menuName = "Module C";
menuURL = "~/Module_C.aspx";
break;
case "ModuleD":
menuName = "Module D";
menuURL = "~/Module_D.aspx";
break;
case "ModuleE":
menuName = "Module E";
menuURL = "~/Module_E.aspx";
break;
case "ModuleF":
menuName = "Module F";
menuURL = "~/Module_F.aspx";
break;
case "ModuleG":
menuName = "Module G";
menuURL = "~/Module_G.aspx";
break;
}
Menu1.Items.Add(new MenuItem { Value = menuName, Text = menuName, NavigateUrl = menuURL });
}
}
}
Screenshot