locked
Panel expand / collapse not maintaining state after postback RRS feed

  • Question

  • User-809753952 posted

    I am using bootstrap collapse class to expand and collapse some panels in a web page.

    They don't maintain their states after post back. How can I prevent it?

    My code is as follows:

     <fieldset  >
                        <legend data-toggle="collapse" data-target="#Panel1" >     [-] Origin</legend>
                        <asp:Panel ID="Panel1" runat="server" CssClass="collapse in  " >
    
    </asp:Panel>
    
    </fieldset>
    
     <fieldset >
                        <legend  data-toggle="collapse" data-target="#Panel2" >     [-] Items</legend>
                        <asp:Panel ID="Pane2" runat="server" CssClass="collapse in " ></asp:Panel>
    
    </fieldset>

    Tuesday, November 3, 2020 9:12 AM

All replies

  • User475983607 posted

    I am using bootstrap collapse class to expand and collapse some panels in a web page.

    They don't maintain their states after post back. How can I prevent it?

    Correct.  The web and HTML controls are stateless.  It is up to you to design and write code to maintain state.  Write a JavaScript function that updates a hidden field or fields that track which elements are expanded.  Add another JavaScript function that expands those fields when the page loads.  

    If you run into trouble, share your code.  Explain how you expect the code to function and what actually happens.  Be sure to debug your code...

    Tuesday, November 3, 2020 12:59 PM