title: Asp.net Ajax Accordion: keep open ajax accordion pan after post back
body: <p>I have used <code>Ajax Accordion</code> control on my <code>Master Page</code> on <code>Page_Load</code> event i want to set <code>SelectedIndex</code> property of <code>Accordion</code> control which i have set inside java script. </p>
  
  <p>My problme is each time in <code>Page_Load</code> event the value of <strong>HiddenField1.Value = " "</strong> that is nothing. i am not getting the value of hidden field which i have set in java script instead i get just notthing or empty string.</p>
  
  <p>Below is hidden field</p>
  
  <pre><code>&lt;asp:HiddenField ID="HiddenField1" runat="Server"  /&gt;
  </code></pre>
  
  <p><strong>NOTE:(1)</strong> I have used <code>HiddenField</code> to complete my task.
  <strong>(2)</strong> I am doing this because <a href="https://stackoverflow.com/questions/3574335/ajax-accordion-loses-current-pane?lq=1">Ajax Accordion Loses Current Pane</a> after post back. </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function pageLoad()
           {
              $find('&lt;%= UserAccordion.ClientID %&gt;' + '_AccordionExtender').add_selectedIndexChanged(onAccordionPaneChanged); 
          }
  
         function onAccordionPaneChanged(sender, eventArgs) 
           { 
             var selPane = sender.get_SelectedIndex();
             document.getElementById('&lt;%=HiddenField1.ClientID%&gt;').value = selPane;
             //alert("SelectedIndex:" + selPane  ); This message fires nicely so i have confirmed that this event work
           }
      &lt;/script&gt;
  </code></pre>
  
  <p>Following is my back end code in <code>.vb</code> file</p>
  
  <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
          If HiddenField1.Value = "" Then
          Else
  
              UserAccordion.SelectedIndex = HiddenField1.Value
  
          End If
  End Sub
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Code of Accordion Control.</p>
  
  <pre><code>&lt;ajax:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
                              HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent"
                              FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250"
                              FramesPerSecond="40" RequireOpenedPane="false" AutoSize="None"  
                              Width="220px" &gt;
                              &lt;Panes &gt;
                                  &lt;ajax:AccordionPane ID="AccordionPane1"  runat="server" &gt;
                                      &lt;Header&gt;
                                          &lt;a href="#" class="href"&gt;ST-ERP Modules&lt;/a&gt;&lt;/Header&gt;
                                      &lt;Content&gt;
                                          &lt;asp:Panel ID="UserReg" runat="server"&gt;
                                              &lt;asp:TreeView runat="server" ID="treeMainMenu" DataSourceID="SiteMapDataSource1"
                                                  NodeIndent="10" Width="150px" OnTreeNodeDataBound="treeMainMenu_TreeNodeDataBound"&gt;
                                                  &lt;ParentNodeStyle Font-Bold="False"&gt;&lt;/ParentNodeStyle&gt;
                                                  &lt;HoverNodeStyle ForeColor="#447BD4" Font-Underline="True"&gt;&lt;/HoverNodeStyle&gt;
                                                  &lt;SelectedNodeStyle HorizontalPadding="0px" ForeColor="#DD5555" VerticalPadding="0px"
                                                      Font-Bold="True" Font-Underline="True"&gt;&lt;/SelectedNodeStyle&gt;
                                                  &lt;NodeStyle NodeSpacing="0px" HorizontalPadding="0px" ForeColor="#447BD4" VerticalPadding="0px"
                                                      Font-Size="8pt" Font-Names="Verdana"&gt;&lt;/NodeStyle&gt;
                                              &lt;/asp:TreeView&gt;
                                          &lt;/asp:Panel&gt;
                                      &lt;/Content&gt;
                                  &lt;/ajax:AccordionPane&gt;
                                  &lt;ajax:AccordionPane ID="AccordionPane2" runat="server"&gt;
                                      &lt;Header&gt;
                                          &lt;a href="#" class="href"&gt;User Detail&lt;/a&gt;&lt;/Header&gt;
                                      &lt;Content&gt;
                                          &lt;asp:Panel ID="Panel1" runat="server"&gt;
                                              &lt;asp:TreeView runat="server" ID="TreeView1" DataSourceID="SiteMapDataSource2" NodeIndent="10"
                                                  Width="150px"&gt;
                                                  &lt;ParentNodeStyle Font-Bold="False"&gt;&lt;/ParentNodeStyle&gt;
                                                  &lt;HoverNodeStyle ForeColor="white" Font-Underline="True"&gt;&lt;/HoverNodeStyle&gt;
                                                  &lt;SelectedNodeStyle HorizontalPadding="0px" ForeColor="#DD5555" VerticalPadding="0px"
                                                      Font-Bold="True" Font-Underline="True"&gt;&lt;/SelectedNodeStyle&gt;
                                                  &lt;NodeStyle NodeSpacing="0px" HorizontalPadding="0px" ForeColor="White" VerticalPadding="0px"
                                                      Font-Size="8pt" Font-Names="Verdana"&gt;&lt;/NodeStyle&gt;
                                              &lt;/asp:TreeView&gt;
                                          &lt;/asp:Panel&gt;
                                      &lt;/Content&gt;
                                  &lt;/ajax:AccordionPane&gt;
                                  &lt;ajax:AccordionPane ID="AccordionPane3" runat="server"&gt;
                                      &lt;Header&gt;
                                          &lt;a href="#" class="href"&gt;Job Details&lt;/a&gt;
                                      &lt;/Header&gt;
                                      &lt;Content&gt;
                                          &lt;asp:Panel ID="Panel2" runat="server"&gt;
                                              ddddddddddddd&lt;/asp:Panel&gt;
                                      &lt;/Content&gt;
                                  &lt;/ajax:AccordionPane&gt;
                              &lt;/Panes&gt;
                          &lt;/ajax:Accordion&gt;
  </code></pre>