Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQUERY - accordion active state asp.net code behind

Tags:

jquery

asp.net

Can anyone inform me how to maintain the jquery accordion active state panel when changing pages. Ideally i would like to change in the code-behind however really happy to just get it working.

developing in asp.net 3.5

Hope this helps

Thanks


2 Answers

Example here. If you select one of the accordion headers then refresh the page the last accordian panel you clicked is opened by default

I see this as a pure client responsibility. I would store the information in a cookie plugin here which you can read and pass to the accordion constructor. I would prefer this over passing values to and from the server for no real benefit.

Something along these lines

//get persisted active accoridan index
var activeIndex  = $.cookie('accordianActiveIndex');

//guard code here to check you have a valid activeIndex...

$('.selector').accordion({
       active: activeIndex,
       change: function(event, ui) { 
           //set cookie here to new active header (index)
           $.cookie('accordianActiveIndex', ui.newHeader.prevAll().length)
      }
});
like image 105
redsquare Avatar answered Aug 28 '26 06:08

redsquare


For anyone with a similar problem getting cookies to work with jQuery UI Accordion, I've solved it by adding one line to redsquare's code.

The cookie value activeIndex needs to be parsed as an integer:

//get persisted active accoridan index
var activeIndex  = $.cookie('accordianActiveIndex');
activeIndex = parseInt(activeIndex, 10);

//guard code here to check you have a valid activeIndex...

$('.selector').accordion({
       active: activeIndex,
       change: function(event, ui) { 
           //set cookie here to new active header (index)
           $.cookie('accordianActiveIndex', ui.newHeader.prevAll().length)
      }
});
like image 29
Paul Avatar answered Aug 28 '26 05:08

Paul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!