0

I've a tree menu.

How can I keep this menu opened after click on the link, after postback?

Obs: I´m using ASP.NET C#

Could you pls help?

jQuery(".menu li").on('click', function (e) {
    e.stopPropagation();

    if (jQuery(this).children().prop("tagName") == "A") {
        jQuery(".menu li a").parent(".item-selected").removeClass('item-selected').addClass('item');
    }

    if (jQuery(this).hasClass('item')) {
        jQuery(this).removeClass('item').addClass('item-selected');
    }

    else if (jQuery(this).hasClass('item-selected')) {
        jQuery(this).removeClass('item-selected').addClass('item');
    }

    jQuery(this).children('ul').slideToggle();
});

Please check this fiddle: http://jsfiddle.net/fzy48/8/

Rodrigo Abib
  • 83
  • 1
  • 2
  • 14

1 Answers1

0

If the link is an actual URL link to a separate page, you can't, exactly. jQuery only applies to the page that you're on. On the other hand, if you want to manage something that looks like that, you can, with a bit of finagling and some server-side dynamic help. Basically, you need to pass the state that you want to preserve (the state of the tree menu, in whatever degree of detail) up to the server, then bounce that same information down to the next page. That page then builds it into the page as a set of dynamically generated javascript var calls. You then put a jQuery function in on pageload that looks for those vars, and sets the menu appropriately. Thus, when you get to the next page, the menu opens up to where you left it.

Ben Barden
  • 2,001
  • 2
  • 20
  • 28