2017-07-17 99 views
0

我通過導航代碼在更新面板使用計時器,但一分鐘後,活動菜單消失,並顯示頁面上沒有活動菜單,但選定的頁面仍然存在....Asp.net菜單導航活動類屬性

讓我分享我的代碼。對於更新面板計數器

代碼 .aspx的代碼:

 <asp:UpdatePanel runat="server" id="UpdatePanel1"> 
      <ContentTemplate> 
      <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer> 



      <nav class="navbar-default navbar-side" role="navigation" style="background-color: #333333; height:100%;"> 
     <div class="sidebar-collapse" style="background-color: #333333; height:100%;"> 
      <ul class="nav" id="main-menu"> 
      <li class="text-center"> 
       <img src="../assets/img/Logo.jpg" class="user-image img-responsive"/>     </li> 


<li> 
        <a class="active-menu" id="MDB" href="ManagerDashBoard.aspx"><i class="fa fa-dashboard fa-3x"></i>Manager DashBoard </a>     
       </li> 


        <li> 
         <a href="#"><i class="fa fa-sitemap fa-3x"></i>Messages<span class="fa arrow"></span></a> 
         <ul class="nav nav-second-level"> 
          <li> 
           <a id="MNMF" href="ManagerNewMessageForm.aspx">Create New Message</a> 
          </li> 
          <li> 
           <a id="MI" href="ManagerInbox.aspx?Status=11">Inbox<span class="in-badge"><asp:Label ID="mgInLabel1" runat="server" Text=""></asp:Label></span> </a> 
          </li> 
          <li> 
           <a id="MS" href="ManagerInbox.aspx?Status=22">Send<span ></span> </a> 
          </li> 

         </ul> 
        </li> 
        <li> 
        <a href="#"><i class="fa fa-sitemap fa-3x"></i>Suggestion Follow Up<span class="fa arrow"></span></a> 
        <ul class="nav nav-second-level"> 

         <li> 
          <a id="MP" href="ManagerNewSuggestion.aspx?Status=7">Pending <span class="mr-badge"><asp:Label ID="SMRPLabel1" runat="server" Text=""></asp:Label></span> </a> 
         </li> 
         <li> 
          <a id="MPP" href="ManagerNewSuggestion.aspx?Status=3">Postpone<span class="pp-badge"><asp:Label ID="PPLabel1" runat="server" Text=""></asp:Label></span> </a> 
         </li> 
         <li> 
          <a id="MAR" href="ManagerNewSuggestion.aspx?Status=6">Archived<span class="ar-badge"><asp:Label ID="SARLabel4" runat="server" Text=""></asp:Label></span></a> 
         </li> 

        </ul> 
        </li> 


        <li> 
        <a href="#"><i class="fa fa-sitemap fa-3x"></i>Account Setting<span class="fa arrow"></span></a> 
        <ul class="nav nav-second-level"> 

         <li> 
          <a id="MAC" href="ManagerAccount.aspx">Account Control</a> 
         </li> 
         <li> 
          <a id="MUP" href="ManagerPassword.aspx">Update Password</a> 
         </li> 

        </ul> 
        </li> 


      </ul> 

     </div> 
     <div style="background-color: #333333; height: 400px;"> 

      </div> 
    </nav> 


</ContentTemplate> 

C#代碼:

public void msgcounter() 
    { 

     SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["FBMNGTConnectionString"].ConnectionString); 
     con.Open(); 

     int msgstatusid = 0; 
     while (msgstatusid < 22) 
     { 

      string strquery2 = string.Empty; 



      strquery2 = "select count(Status) as msgcntstatus from MessageApprovalTable where Status = " + msgstatusid + " and ToEmployee_ID =" + Session["Employee_Id"]; 





      SqlCommand cmd2 = new SqlCommand(strquery2, con); 

      SqlDataAdapter sda = new SqlDataAdapter(cmd2); 
      DataSet ds = new DataSet(); 

      sda.Fill(ds); 


      string mgcount = Convert.ToString(ds.Tables[0].Rows[0]["msgcntstatus"]); 


      switch (msgstatusid) 
      { 
       case 11: 

        mgInLabel1.Text = Convert.ToString(mgcount); 

        break; 
       //case 22: 
       // mngsndLabel1.Text = Convert.ToString(mgcount); 
       // break; 
       //case "2": 
       // strquery += " where Suggestion_Status = 2"; 
       // break; 

       default: 
        break; 

      } 





      msgstatusid++; 
     } 

    } 



    protected void Timer1_Tick(object sender, EventArgs e) 
    { 
     counter(); 
     msgcounter(); 
    } 

回答

0

請添加下面一行的Timer_Tick, 說,菜單ID:MDB; Runat =「服務器」

MDB.attributes.add(「class」,「active-menu」);

所有頁面你可以採取href的值或頁面名稱有關菜單項

+0

應用主動類在那裏我會把這個? – Umer

+0

將id和runat =「server」分配給Htmltag,並將此代碼寫入代碼後面。 MDB是控制的ID –