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

后端 未结 13 2101
遥遥无期
遥遥无期 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:09

    You could use a hidden input field to persist the active accordion index during postbacks, and then populate it using javascript during the change event of the accordion.

    
    
    
    

    You could probably come up with a more efficient way of capturing the active index during the change event, but this seems to work.

    When the page has loaded it retrieves the active index from the hidden field and stores it in a variable. It then initialises the accordion using the retrieved index and a custom function to fire on the change event which writes a new index to the hidden field whenever a new pane is activated.

    During a postback, the hidden field value is persisted in the ViewState so that when the page is loaded again the accordion is initialised with the index of the last pane clicked on.

提交回复
热议问题