Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6672647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:31:58+00:00 2026-05-26T03:31:58+00:00

I have a Navigation menu using ul and li.. i am able to populate

  • 0

I have a Navigation menu using ul and li.. i am able to populate it but it cannot remember its state once postback happens or if i move to a new page.

Here is the code:

Masterpage.Master

 <ul id="main-nav">         

            <li> 
                <a href="MPTest2.aspx" class="nav-top-item" runat="server"> 
                Employees
                </a>
                <ul id="mgList" runat="server" >

                </ul>

            </li>
</ul>

MasterPage.Master.cs

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(@"Data Source= localhost;Initial Catalog=ServerDb;Integrated Security=True");
        connection.Open();
        SqlCommand sqlCmd = new SqlCommand("select EmpName, EmpID from Employee order by EmpName", connection);
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

        sqlDa.Fill(dt);
        connection.Close();
        if (dt.Rows.Count > 0)
        {
            HtmlGenericControl li;

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                li = new HtmlGenericControl("li");

                HtmlAnchor a = new HtmlAnchor();
                a.HRef = "~/MPTest1.aspx?MGID=" + Convert.ToInt32(dt.Rows[j]["EmpID"]);
                a.InnerText = dt.Rows[j]["EmpName"].ToString();
                li.Controls.Add(a);
                mgList.Controls.Add(li);
            }
        }          
    }

JQuery:

$(document).ready(function(){

//Sidebar Accordion Menu:

    $("#main-nav li ul").hide(); // Hide all sub menus


    $("#main-nav li a.nav-top-item").click( // When a top menu item is clicked...
        function() {
            $(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
            $(this).next().slideToggle("normal"); // Slide down the clicked sub menu
            return false;
        }
    ); }

Now i know the hide() function hides all the menus which is needed to be called the first time. But after that i need a class or function which remembers the state of the menu if it was open rather than collapsing everything.

It would be great if i could get some suggestions or some examples.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:31:59+00:00Added an answer on May 26, 2026 at 3:31 am

    I know this isn’t exactly what you are looking for but it is what I use to track my menu/submenu activeness. I believe you should be able to use the premise I provide below to show the correct menu items. I might also not be understanding the question, if that is the case please let me know and I’ll try to help further. The example below is being used with Razor MVC3.

    I’d also like to point out that I have limited myself to two levels of menus for this code and if you use more than that you should modify the code to be more recursively robust.

    $(function () {
            $("#menu li a[href='@Request.Url.LocalPath'],#menu li a[href='@(Request.Url.PathAndQuery)']").parent("li").addClass("current_page_item");
            $("li.current_page_item").parent("ul").parent("li").addClass("current_page_item");
        });
    

    In the theme of your below comment I believe you could do something like the following which is not perfect but may give you a start in the right direction.

    [WebMethod]
    public static string MarkOpened(string id)
    {
        HttpContext.Current.Session["currentPage"] = id
    }       
    
    $(document).ready(function(){
        $("#main-nav li a.nav-top-item:<%= HttpContext.Current.Session["currentPage"] %>").next().slideToggle("normal"); 
        $("#main-nav li a.nav-top-item").click(function(){
            $.ajax({
                type: "POST",
                url: location.href + "/MarkOpened",
                contentType: "application/json; charset=utf-8",
                data: "{ 'id':'" + $(this).attr("something") + "'}",
                dataType: "json"
            });
        };
    ); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a navigation system using jquery scrollto. I have my navigation menu in
i am styling a navigation menu using the following css. I have found that
using ASP.NET MVC 2 I have a navigation menu inside my Master Page. In
I have navigation menu using images, I want that if the user click a
I have annoying problems using django-sitetree (version 0.5.1) for generating a navigation menu with
I have a navigation menu defined in visual web developer 2010 express using a
I have a left side navigation menu on my page.. using url.action like below..
I have a navigation menu provider that I am trying to move over to
I have a navigation menu using nested ul . When the top ul is
i have a navigation menu and i am using the hover element to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.