I have a bootstrap 3.x accordion(collapse) on a page where I'm trying to get users to be able to add/edit a lot of information without a ton of scrolling. Some of this information is dependant on the rest so I've got an UpdatePanel within one of the accordion tabs. Either the updatpanel isn't doing its thing properly or it just doesn't play nice with the accordion in some other way.
Here's the basic accordion code:
<div class="panel-group" id="ccAccordion" role="tablist" aria-multiselectable="true">
<asp:Panel ID="pnlAddress" runat="server" class="panel panel-default">
<div class="panel-heading" role="tab" id="billAddressHeading">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#ccAccordion" href="#billToAddressTab" aria-expanded="false" aria-controls="billToAddressTab">
<asp:Literal ID="BillToAddressLabelTxt" runat="server" Text="Bill Address" />
</a>
</h4>
</div>
<div id="billToAddressTab" class="panel-collapse collapse" role="tabpanel" aria-labelledby="billAddressHeading">
<div class="panel-body">
<!-- Other controls -->
</div>
</div>
</asp:Panel>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="thirdPartyHeading">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#ccAccordion" href="#thirdPartyTab" aria-expanded="false" aria-controls="thirdPartyTab">
<asp:Literal ID="ThirdPartyShippingLabelTxt" runat="server" Text="Shipping Accounts" />
</a>
</h4>
</div>
<div id="thirdPartyTab" class="panel-collapse collapse" role="tabpanel" aria-labelledby="thirdPartyHeading">
<div class="panel-body">
<asp:UpdatePanel runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddShipAccount" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnSaveSABA" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnAddShipAccountNo" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnAddShipAccount" runat="server" CssClass="btn btn-success" Text="Add New Shipping Account"
OnClick="btnAddShipAccount_Click" /><!-- moved from inside panel -->
<asp:Panel ID="pnlBranchShipping" runat="server" DefaultButton="btnSaveSABA">
<div class="panel panel-default">
<div class="controls">
<div class="form-group">
<!-- Other controls -->
</div>
<asp:panel ID="pnlAddEditAcct" CssClass="controls" runat="server" Visible="false">
<!-- Other controls -->
<div>
<asp:LinkButton ID="btnSaveSABA" Text="Save" runat="server" ValidationGroup="vgSAB" OnClick="btnSaveSABA_Click"
CssClass="btn btn-default" />
</div>
<div class="form-group">
<asp:Button ID="btnAddShipAccountNo" runat="server" CssClass="btn btn-default" Text="Add Shipping Account" OnClick="btnAddShipAccountNo_Click"
ValidationGroup="vgShipAccount" />
</div>
</asp:panel>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="vatHeading">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#ccAccordion" href="#vatTab" aria-expanded="false" aria-controls="vatTab">
<asp:Literal ID="VatNumberLabelTxt" runat="server" Text="Tax Ids" />
</a>
</h4>
</div>
<div id="vatTab" class="panel-collapse collapse" role="tabpanel" aria-labelledby="vatHeading">
<div class="panel-body">
<asp:Panel ID="pnlTaxId" runat="server" class="form-group" DefaultButton="btnAddTaxId">
<!-- Other controls -->
</asp:Panel>
</div>
</div>
</div>
</div>
What happens when you click any of the buttons inside is it basically refreshes the whole page and the accordion goes back to its original state, but the the things the button did (showing additional fields, for example) are visible when you open up the tab again.
Update
I realized today that the whole bit of code above is within another UpdatePanel which is in the MasterPage. This UpdatePanel has all the default settings, so the postback in my code above was triggering the parent. I'm guessing to get around this I'm going to have to change the way the whole form operates.
I actually ended up using the solution in THIS answer: https://stackoverflow.com/a/25258290/727857
Again this is for Bootstrap 3.x.x and requires jquery-cookie.js from https://github.com/carhartl/jquery-cookie
Edited to add the full text of the answer above in case the link dies:
Sample HTML for accordion:
Javascript (jquery) to retain the state of the tabs in this accordion:
I don't know whether dshapiro's answer will work or is better, but this is less javascript and could easily be made into a function which is repeatable on different pages.
I ran into the same problem and used the following bit of custom code to resolve it.
Which references the below utility js:
And is initialized like so:
The idea being that you can create a custom state manager for any controls which are causing you trouble (tab and accordion for me), wire it up in your initialization logic, and it'll get handled in any update panel.