如何在页面加载时控制两个div。一个div将一次显示..我需要它在asp.net登录和注销会话..
这是我的代码,在loggin之后,它显示了两个div ..在注销后,只显示了一个div
Master page.master.cs
protected void Page_Load(object sender, EventArgs e)
{
isset.Visible = notsesstion.Visible = false;
if (!String.IsNullOrEmpty(Session["name"] as String))
{
lbllogin.Text = "Welcome Back " + Session["name"].ToString();
isset.Visible = true;
notsesstion.Visible = false;
}
else
isset.Visible = false;
notsesstion.Visible = true;
}
Masterpage.aspx
<nav class="navbar navbar-default navbar-fixed-top">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="HomePageClient.aspx">
<img alt="Brand" src="images/logo2.png" height="50" />
</a>
</div>
<div id="notsesstion" runat="server">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="LogIn.aspx" class="glyphicon glyphicon-lock">LogIn |</a></li>
<li><a href="EmployeeRegistration.aspx" class="glyphicon glyphicon-user">Employee |</a></li>
<li><a href="UserRegistration.aspx" class="glyphicon glyphicon-user">Client</a></li>
</ul>
</div>
</div>
<div id="isset" runat="server">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><p><asp:Label ID="lbllogin" runat="server" Text=""></asp:Label></p></li>
<li><a href="LogOut.aspx" class="glyphicon glyphicon-user" >LogOut</a></li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:0)
这样的事情:
<% if (!String.IsNullOrEmpty(Session["name"] ){ %>
// html code here
<% } %>