I have a Bootstrap Accordion inside an UpdatePanel. When the page PostBack, the Accordion is lost and not functioning as expected. I suspect it is because of the partial postback that recreates the Accordion elements.
I need to know how to create the Accordion by Javascript?
But if a post-back is collapsing the according, then how would creating one via code make any difference?
I mean, you can add code to "save" the users selection.
so, above has a button (post back).
But, note how we "save" the click selection into a hidden field.
That way the value persists.
Even better, our button click event could for example show, open the 3rd value with the above setup.
so, so this:
And code behind is this:
So, now when we click that button, we have a post-back and we set the panel
so, we see this:
So, note how we add a click event to the panel select, and SAVE that into a hidden field.
This not only allows code behind to get what panel is dropped (open), but it also means we can set the value of the hidden field, and the panel will open to that selection.
However, I fail to see how writing code would solve your problem, since if you added the accordion by code, YOU STILL will require code to persist (save) the current selection to survive post-backs.
so, better is just to setup a hidden field. the beauty of the above, is you have automatic setting and code behind at any time can get the current dropped section with:
And to set the value then
And since we "save" the current seleciton into that hidden field?
Well, if we don't touch or set ActivePanel, it will still work, and still remember the users current choice/setting - even with post-backs on the page.
You can introduce a update panel, but the above will work regardless as such anyway.