How do I make navbar button invisible upon admin log in
I am trying to make a button on my navbar to become invisible when a user is not admin. Here is the code I used on Page Load event
public partial class Home : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
showdata();
}
public void showdata()
{
int temp = 0;
if (temp == 1)
{
cmd.CommandText = "select * from Users where email= '" + Session["user"] + "'";
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(ds, "detail");
if (ds.Tables[0].Rows.Count > 0)
{
string UserRole;
UserRole = dt.Rows[0][4].ToString().Trim();
if (UserRole == "U")
{
lipaybutton.Visible = false;
}
if (UserRole == "A")
{
lipaybutton.Visible = true;
}
}
}
}
Then here is my HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Home</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'/>
<link href='https://fonts.googleapis.com/css?family=Nunito' rel='stylesheet'/>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<style type="text/css">
.dropdown:hover {
display: block;
}
.navbar{
width:100%;
position:fixed!important ;
top:0px;
}
@media(min-width:992px){
.col-md-6:not(:first-child) {
}
.col-md-6:not(:last-child) {
border-right:1px solid #200662;
border-left:1px;
}
.form-horizontal {
line-height: 1.33;
letter-spacing: -.5px;
margin-bottom: 5px;
margin-top:0%;
}
}
</style>
</head>
<body style=" background-color:#DCDCDC; background-image:url('images/Dox.png'); overflow-x:no-display;">
<form id="form1" runat="server">
<div class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation" style="background-color: #00003D; font-family: 'Comfortaa';">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" style="background-color: #00003D; border-color: white; border-width: 1px; color: white">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="Home.aspx" style="color: #FFFFFF; font-size: small; border-right: solid 1px #555; border-left: solid 1px #111;">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><asp:Label ID="user" runat="server" Font-Size="smaller" Text="" ForeColor="White"></asp:Label><img alt="" src="images/img1.jpg" height="20" /><b class="caret"></b></a>
<ul class="dropdown-menu" style="background-color: #00003D;">
<li class="dropdown-header" id="dashB"><a href="DashBoard.aspx" style="color: #FFFFFF; font-size: small; background-color: #00003D;">Admin Dashboard</a></li>
</ul>
</li>
<li>
<a><asp:Label ID="Units" runat="server" Font-Size="smaller" ForeColor="White"></asp:Label></a>
</li>
<li class="dropdown" style="margin-right: 10px;">
<script src="https://js.paystack.co/v1/inline.js"></script>
<asp:Button type="button" ID="lipaybutton" runat="server" class="btn btn-primary navbar-btn" Text="Wallet Deposit" Style="width: 115px; font-size: smaller;" OnClick="paybutton_Click" />
</li>
</ul>
</div>
</div>
</div>
</form>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>