Asp.net 菜单导航已激活 class 属性

Asp.net Menu navigation active class property

我使用计时器将导航代码放入更新面板,但一分钟后活动菜单消失并且页面上没有显示任何活动菜单但所选页面仍然存在....

让我分享我的代码..

更新面板计数器代码 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();
    }

请在 Timer_Tick 中添加以下行, 放 ,Menu id : MDB ; Runat="Server"

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

对于所有页面您可以在菜单项

上获取 href 值或页面名称以应用活动 class