Keep the current jQuery accordion pane open after ASP.NET postback?

后端 未结 13 2140
遥遥无期
遥遥无期 2020-12-09 09:57

I have a jquery accordion on an asp.net aspx weppage. Inside the panes, I have asp.net buttons. When I click on the button, the pane I was in, closes and reloads the page,

13条回答
  •  醉话见心
    2020-12-09 10:31

    MaxCarey's solution seems to work well, but the latest version of jQuery UI (1.10.4) seems to have some differences. The correct event is not "changed" now, but "activate" (or "beforeActivate", if you want the option to cancel the event).

    
    ...
    
    $(document).ready(function () {
        var activeIndex = parseInt($("#<%=hidAccordionIndex.ClientID %>").val());
    
        $("#accordion").accordion({
            heightStyle: "content",
            active: activeIndex,
            activate: function (event, ui) {
                var index = $(this).children('h3').index(ui.newHeader);
                $("#<%=hidAccordionIndex.ClientID %>").val(index);
            }
        });
    });
    

    The gotcha for me here is that I can verify that the hidAccordionIndex value is being set to the proper value, but on postback, it's getting set back to 0 no matter what I try. I've tried setting it to an empty string, like Dave.Lebr1 suggested, but it still isn't persisting on postback.

    This should remain available on postback, since my divAccordionIndex field should have ViewState (I've verified it's enabled).

    Has anyone else had success with this? This menu is in my master page, and it works great...other than this.

提交回复
热议问题