What Im trying to do is to hide the login button in masterpage header when the user logged in. Below are the codes.
SiteMaster.Master.aspx
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteMaster.Master.cs" Inherits="UniSystem.SiteMaster" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<title><%: Page.Title %> - UniSystem Database - </title>
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
</head>
<body>
<form runat="server">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top">
<div class="container-fluid">
<a class="navbar-brand ps-5" runat="server" href="~/">Home</a>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item"><a runat="server" class="nav-link fs-5 gap-2" href="~/AdminModule/RegisterLecturer/Lecturer.aspx">Register Lecturer</a></li>
<li class="nav-item"><a runat="server" class="nav-link fs-5 gap-2" href="~/LecturerModule/LecturerWorkload/WorkloadLec.aspx">Lecturer Page</a></li>
<li class="nav-item"><a runat="server" class="nav-link fs-5 gap-2" href="~/Login/LoginPage.aspx">Login</a></li>
<li class="nav-item"><a runat="server" class="nav-link fs-5 gap-2" href="~/Contact">Contact</a></li>
</ul>
<div class="d-grid gap-2 d-md-flex justify-content-md-end pe-5">
<asp:LinkButton ID="btnlogin" class="btn btn-outline-danger me-md-2 fs-5" runat="server" PostBackUrl="~/Login/LoginPage.aspx">Login</asp:LinkButton>
</div>
</div>
</div>
</nav>
<div class="container body-content pt-3">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<hr />
<footer>
<p>© <%: DateTime.Now.Year %> - Designed by MAMK-CI190019</p>
</footer>
</div>
</form>
</body>
</html>
SiteMaster.Master.aspx.cs
namespace UniSystem
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public LinkButton btnlogin
{
get
{
return this.btnlogin;
}
}
LoginPage.aspx
<%@ Page Title="Login" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true" CodeBehind="LoginPage.aspx.cs" Inherits="UniSystem.LoginPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<!DOCTYPE html>
<link rel="stylesheet" href="/Login/css/Login.css"/>
<div style="height: 150px; width: 980px;">
<h2 position: absolute; left: 100px; top: 150px;>
Login Page
</h2>
<asp:Label ID="lblLoginID" Runat="server" Text='ID' style="font-size: medium"></asp:Label>
<asp:TextBox ID="txtLoginID" runat="server" Width="240px"></asp:TextBox>
<br />
<br />
<asp:Label ID="lblLoginPass" Runat="server" Text='Password' style="font-size: medium"></asp:Label>
<asp:TextBox ID="txtLoginPass" runat="server" Width="240px" ></asp:TextBox>
</div>
<div class ="radiopad">
<asp:RadioButtonList ID="rblDBSelect" runat="server">
<asp:ListItem Text="Student" Value="Student" />
<asp:ListItem Text="Lecturer" Value="Lecturer" />
<asp:ListItem Text="Admin" Value="Admin" />
</asp:RadioButtonList>
</div>
<div class ="radiopad">
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
<br />
<asp:Label ID="lblAttention" runat="server" CssClass="Note"></asp:Label>
</div>
</asp:Content>
LoginPage.aspx.cs
namespace UniSystem
{
public partial class LoginPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
LoginPageC std = new LoginPageC();
string txtloginid = txtLoginID.Text;
string txtloginpass = txtLoginPass.Text;
string selectTbl = rblDBSelect.SelectedItem.Value.ToString();
{
if (txtloginid.Trim() == "" && txtloginpass.Trim() == "")
{
lblAttention.Text = "Please Insert Data Completely!";
}
else
{
if (std.LoginValidation(txtloginid, txtloginpass, selectTbl) == false)
{
lblAttention.Text = " *Wrong Credentials";
}
else
{
string selTbl = std.GetSelectedTbl();
if (selTbl == "Lecturer")
{
Session["loginid"] = std.GetLoginID();
Response.Redirect("/LecturerModule/LecturerWorkload/WorkloadLec.aspx");
}
else if (selTbl == "Admin")
{
Session["loginid"] = std.GetLoginID();
Response.Redirect("/AdminModule/RegisterLecturer/Lecturer.aspx");
}
else if (selTbl == "Student")
{
Response.Redirect("Student.aspx");
}
else
{
lblAttention.Text = " *Please Select A Role";
}
}
}
}
}
}
}
WorkloadLec.aspx / aka lecturer dashboard
<%@ Page Title="WorkloadLec" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true" CodeBehind="WorkloadLec.aspx.cs" Inherits="UniSystem.WorkloadLec" %>
<%@ MasterType VirtualPath="~/SiteMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<!DOCTYPE html>
<div style="height: 800px; width: 980px;">
<h2 position: absolute; left: 100px; top: 150px;>
Register Lecturer
</h2>
<br />
<asp:datagrid id="dgLecturerWorkload" runat="server" BackColor="White" BorderStyle="Solid"
BorderColor="Transparent" AutoGenerateColumns="False" Width="980px" ShowFooter="True"
OnItemDataBound="dgLecturerWorkload_ItemDataBound" OnItemCommand="dgLecturerWorkload_ItemCommand"
AllowPaging="True" OnPageIndexChanged="dgLecturerWorkload_PageIndexChanged" Height="300px">
<AlternatingItemStyle CssClass="Even_Row_Admin"></AlternatingItemStyle>
<HeaderStyle CssClass="Table_Header_Admin"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="No">
<HeaderStyle Font-Bold="True"/>
<ItemTemplate>
<%# (dgLecturerWorkload.PageSize*dgLecturerWorkload.CurrentPageIndex)+ Container.ItemIndex+1%>
</ItemTemplate>
<ItemStyle Width="5%" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Subject">
<HeaderStyle Font-Bold="True"/>
<ItemTemplate>
<asp:Label ID="lblSubjectName" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "SUBJECT_NAME") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50%" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Create Assignment/Tutorial">
<HeaderStyle Font-Bold="True"/>
<ItemTemplate>
<asp:Button ID="btnCreateAsgnmt" Runat="server" CommandName="CreateAsgnmt" Text="Create" />
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Quiz True/False">
<HeaderStyle Font-Bold="True"/>
<ItemTemplate>
<asp:Button ID="btnResultQuizTF" Runat="server" CommandName="ResultQuizTF" Text="Result" />
<asp:Button ID="btnCreateQuizTF" Runat="server" CommandName="CreateQuizTF" Text="Create/View Quiz" />
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Quiz Objective">
<HeaderStyle Font-Bold="True"/>
<ItemTemplate>
<asp:Button ID="btnResultQuizObj" Runat="server" CommandName="ResultQuizObj" Text="Result" />
<asp:Button ID="btnCreateQuizObj" Runat="server" CommandName="CreateQuizObj" Text="Create/View Quiz" />
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages" />
</asp:datagrid>
<asp:DropDownList ID="ddlLecturerWorkload" runat="server" ></asp:DropDownList>
<br />
<br />
<br />
<asp:Label ID="lblAttention" runat="server" CssClass="Note"></asp:Label>
</div>
<div class="center" style="width: 980px; height: 59px;">
Centered
</div>
</asp:Content>
WorkloadLec.aspx.cs
namespace UniSystem
{
public partial class WorkloadLec : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["loginid"] != null)
{
{
Master.btnlogin.Visible = false;
}
}
if (!IsPostBack)
{
SetupSubject();
}
}
public void SetupSubject()
{
dgLecturerWorkload.ShowFooter = true;
WorkloadLecC std = new WorkloadLecC();
DataSet ds = std.GetDisplaySubj();
dgLecturerWorkload.DataSource = ds.Tables["SUBJECT"];
dgLecturerWorkload.DataBind();
ArrayList arAnswerEyeList = std.SelecSubj("", "");
ddlLecturerWorkload.DataSource = arAnswerEyeList;
ddlLecturerWorkload.DataTextField = "Value";
ddlLecturerWorkload.DataValueField = "Key";
ddlLecturerWorkload.DataBind();
}
protected void dgLecturerWorkload_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgLecturerWorkload.CurrentPageIndex = e.NewPageIndex;
SetupSubject();
}
protected void dgLecturerWorkload_ItemDataBound(object source, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.FindControl("DeleteUser") != null)
{
((Button)e.Item.FindControl("btnDeleteUser")).Attributes.Add("onClick", "return confirm('Are you sure wish to delete the data?');");
}
}
protected void dgEdit_Student(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgLecturerWorkload.EditItemIndex = e.Item.ItemIndex;
SetupSubject();
}
protected void dgCancel_Student(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgLecturerWorkload.EditItemIndex = -1;
SetupSubject();
}
}
}
}
So when a user clicks the login button in the masterpage, it will redirect to loginpage.aspx, then from the login page, it redirects to WorkloadLec.aspx like a dashboard. As the dashboard also displays the same navbar from the masterpage, i want to hide the login button after user logged in. However, StackOverflowException is being thrown at the return.this.btnlogin.
I follow all the steps in https://www.youtube.com/watch?v=GrKZ2YFsr8s but still cant get it to work. Please help me.