2016-08-14 224 views
0

如何在頁面加載時控制兩個div。一個div將顯示在一個時間..我需要它的登錄和註銷會話在asp.net ..頁面加載隱藏div並顯示另一個

這是我的代碼,在登錄後,它顯示兩個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

事情是這樣的:

<% if (!String.IsNullOrEmpty(Session["name"]){ %>    
    // html code here 
<% } %> 
相關問題