Maintaining Accordion panel selected state between pageshttp://forums.asp.net/t/1164172.aspx/1?Maintaining+Accordion+panel+selected+state+between+pagesWed, 27 Aug 2008 08:12:54 -040011641721932163http://forums.asp.net/p/1164172/1932163.aspx/1?Maintaining+Accordion+panel+selected+state+between+pagesMaintaining Accordion panel selected state between pages <p>Hi,</p> <p>I have a master page that I'm setting up.&nbsp; On the left side is an accordion control.&nbsp; This is going to server as my menu for the website.&nbsp; When the user clicks on a panel header, obviously, the content opens up.&nbsp; I could link to PDF's, HTML, ASPX, etc.&nbsp; When they click on a link to another page in my website, it does a postback.&nbsp; Now in a perfect world, if they were in Accordion &quot;Panel C&quot; when they clicked on that link to another page in my site, it would do the postback, that page would be displayed, and the content under &quot;Panel C&quot; would still be shown.&nbsp; However, I can't get that to work.&nbsp; If I set selectedindex on the header to -1 or 0, it doesn't do what I want it to do.&nbsp; I had EnableViewState set to true at one point and I couldn't get that to work.&nbsp; So, how do I maintain which panel was open between postbacks?&nbsp; Any feedback would be appreciated.</p> <p>A partial snippet of my code:<br> </p> <p>&lt;ajaxToolkit:Accordion ID=&quot;Accordion1&quot; runat=&quot;server&quot; AutoSize=&quot;None&quot; FadeTransitions=&quot;false&quot; Width=&quot;100%&quot; HeaderCssClass=&quot;accordionHeader&quot; ContentCssClass=&quot;accordionContent&quot; RequireOpenedPane=&quot;false&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;Panes&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;ajaxToolkit:AccordionPane ID=&quot;AccordionPane1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;Header&gt;&lt;a href=&quot;&quot; onclick=&quot;return false;&quot;&gt;About&lt;/a&gt;&lt;/Header&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Content&gt;Item 1&lt;br /&gt;Item 2&lt;br /&gt;Item 3&lt;/Content&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/ajaxToolkit:AccordionPane&gt;<br> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;ajaxToolkit:AccordionPane ID=&quot;AccordionPane5&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;Header&gt;&lt;a href=&quot;&quot; onclick=&quot;return false;&quot;&gt;Luminaria&lt;/a&gt;&lt;/Header&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Content&gt;Item 1&lt;br /&gt;Item 2&lt;br /&gt;Item 3&lt;/Content&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ajaxToolkit:AccordionPane&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;ajaxToolkit:AccordionPane ID=&quot;AccordionPane7&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Header&gt;&lt;a href=&quot;&quot; onclick=&quot;return false;&quot;&gt;Help&lt;/a&gt;&lt;/Header&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Content&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;p&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;asp:HyperLink ID=&quot;lnkFAQ&quot; runat=&quot;server&quot; NavigateUrl=&quot;&quot;&gt;Frequently Asked Questions (FAQ)&lt;/asp:HyperLink&gt;&lt;br /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:HyperLink ID=&quot;lnkDirections&quot; runat=&quot;server&quot; NavigateUrl=&quot;&quot;&gt;Driving Directions&lt;/asp:HyperLink&gt;&lt;br /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:HyperLink ID=&quot;lnkContact&quot; runat=&quot;server&quot; NavigateUrl=&quot;~/help/contactus.aspx&quot;&gt;Contact Us&lt;/asp:HyperLink&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/p&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/Content&gt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/ajaxToolkit:AccordionPane&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp; &lt;/Panes&gt;<br> &lt;/ajaxToolkit:Accordion&gt;</p> <p>The problem can be viewed in action, if you like, by going to southportlandrelay.org.&nbsp; Site's still in development, so there's next to nothing out there at the moment, but you can see the problem.&nbsp; Click &quot;Help&quot; and the menu pops up.&nbsp; Click the &quot;Contact Us&quot; item, and you'll be taken to that page, but instead of having the &quot;Help&quot; menu still open, the &quot;About&quot; one is.</p> <p>What am I missing here?&nbsp; Thanks in advance!&nbsp;</p> 2007-09-28T16:03:53-04:001932337http://forums.asp.net/p/1164172/1932337.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>According to <a class="" href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Accordion/Accordion.aspx"> Accordion Sample</a>: <em>&quot;We keep track of the selected pane so it stays visible across postbacks.&quot;</em></p> <p>Is it a postback or are you navigating to another page?</p> <p>-Damien</p> 2007-09-28T17:31:04-04:001932705http://forums.asp.net/p/1164172/1932705.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks Yes, I'm navigating to another page each time.&nbsp; Sorry about that.&nbsp; I just renamed the subject of this message to reflect the correction.<br> 2007-09-28T21:22:44-04:001932905http://forums.asp.net/p/1164172/1932905.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>&nbsp;</p> <blockquote><span class="icon-blockquote"></span> <h4>Bubba627</h4> Yes, I'm navigating to another page each time.&nbsp; </blockquote> <p></p> <p>In that case it won't work; it's not a postback...&nbsp; You're going to need to set the selected pane on each page, for example passing the index to the query string or storing in Session or something.</p> <p>-Damien</p> 2007-09-29T02:10:07-04:001933150http://forums.asp.net/p/1164172/1933150.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p></p> <blockquote><span class="icon-blockquote"></span> <h4>dwhite</h4> <p></p> <p>&nbsp;</p> <blockquote><span class="icon-blockquote"></span> <h4>Bubba627</h4> Yes, I'm navigating to another page each time.&nbsp; </blockquote> <p></p> <p>In that case it won't work; it's not a postback...&nbsp; You're going to need to set the selected pane on each page, for example passing the index to the query string or storing in Session or something.</p> <p>-Damien</p> <p></p> </blockquote> &nbsp; <p></p> <p>Pardon my ignorance here.&nbsp; So what event do I code for to catch this?&nbsp; I don't see an OnClick associated with anything related to the Accordion.&nbsp; What's the event (or what are the events) that I hook storing this in Session into?</p> <p>Many thanks for continuing to help me work through this.<br> &nbsp;</p> 2007-09-29T12:27:48-04:001933168http://forums.asp.net/p/1164172/1933168.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>The property you need to store and <a class="" href="http://www.asp.net/ajax/ajaxcontroltoolkit/samples/Accordion/Accordion.aspx"> set is &quot;<em>SelectedIndex&quot;</em></a>.&nbsp; To set this, you can just do it in the Page_Load, but remember to use if(!Page.IsPostBack) since you only want it to fire the first time.&nbsp; To set the SelectedIndex, you can basically do this anywhere assuming you are using something that posts back (e.g. Page_Load, LinkButton_Click, etc); you don't need a specific event to get the value.&nbsp;&nbsp;&nbsp; </p> <p>Hope this helps.</p> <p>-Damien</p> 2007-09-29T13:16:14-04:001933882http://forums.asp.net/p/1164172/1933882.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>Sorry, but this one seems to be avoiding me.&nbsp; Please bear with me here.<br> </p> <p>I set up a link button in one of the panels on my master page.&nbsp; It's coded as this:</p> <p>&lt;asp:LinkButton ID=&quot;lbContact&quot; runat=&quot;server&quot; OnClick=&quot;Foo&quot; PostBackUrl=&quot;~/help/contactus.aspx&quot;&gt;LinkButton&lt;/asp:LinkButton&gt;</p> <p>I set a breakpoint in my Foo method, and all that does is this:</p> <p>ViewState[&quot;SelectedPanel&quot;] = Accordion1.SelectedIndex;</p> <p>That method never gets hit.&nbsp; That line never gets executed.&nbsp; I still can't figure out how to get this to work.</p> <p>You say I can store this in the Page_Load method, but the user doesn't select anything until after the page has already loaded, right?&nbsp; Then they could make multiple selections, showing one panel, then another, then another before they finally click on one of my menu items.&nbsp; I don't get how setting this in page load takes care of it.&nbsp; Don't I actually need a specific event to get the value, with that event being whichever menu item they click, so I know which pane it's in, so I know to save that value?<br> </p> <p>What am I missing here?&nbsp; Again, thanks for helping me work through this.<br> </p> 2007-09-30T15:09:29-04:001933941http://forums.asp.net/p/1164172/1933941.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>As far as I know an asp button doesn't execute client site code. It only posts back and execute server site code.<br> Maybe you try out a &quot;normal&quot; html button with runat=server. The button can execute your javascript function on client site and then execute the server site code.</p> <p>&nbsp;e.g.:</p> <p>Client code:<br> &nbsp;</p> <pre class="prettyprint">&lt;input type=&quot;button&quot; id=&quot;lbContact&quot; onClick=&quot;Foo();&quot; runat=&quot;server&quot; /&gt;</pre>Server code:<br><br>&nbsp;<pre class="prettyprint"><span class="kwd">Protected WithEvents</span> lbContact <span class="kwd">As</span> HtmlInputButton<br><span class="kwd">Private Sub</span> lbContact_ServerClick(<span class="kwd">ByVal</span> sender <span class="kwd">As Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.EventArgs) <span class="kwd">Handles</span> lbContact.ServerClick<br> <span class="cmt">'Do what ever you want...</span><br> <span class="kwd">MyBase</span>.Response.Redirect(<span class="st">"~/help/contactus.aspx?SelectedIndex="</span> &amp; Accordion1.SelectedIndex)<br><span class="kwd">End Sub</span></pre><p>Or&nbsp; you can do it all on client site:</p><p>&nbsp;</p><pre class="prettyprint">function Foo() { location.href = "~/help/contactus.aspx?SelectedIndex=" &amp; Accordion1.SelectedIndex; }</pre>&nbsp;&nbsp;<pre class="prettyprint"><br>Hm, or maybe you only forgot the Foo<b style="color: red;">();</b><br><br>** Marcus&nbsp;</pre> 2007-09-30T16:56:55-04:001937731http://forums.asp.net/p/1164172/1937731.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks Hey, thanks for your input on this.&nbsp; I won't be able to get a chance to try it until later this week.&nbsp; I'll post an update and ask any new questions as necessary.&nbsp; Thanks again!&nbsp; Stay tuned!<br> 2007-10-03T00:14:15-04:001943557http://forums.asp.net/p/1164172/1943557.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>Hi,</p> <p>So is there any way to do this without using the querystring?&nbsp; I'd like to keep the URL as &quot;clean&quot; as possible, if I can, and keep querystrings out of it.&nbsp; Is it just not possible to use the Accordion control the way I envisioned I could?<br> &nbsp;</p> 2007-10-05T19:54:11-04:001943829http://forums.asp.net/p/1164172/1943829.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>To pass the index on to another page, you need to maintain the index some way between pages.&nbsp; Querystring is one way to do it, but you can also use Session variables, or even a cookie.&nbsp; See <a href="http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/">http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/</a>&nbsp;for more info.&nbsp; In your case using the querystring is the best option, but if you don't want to use it then go with Session.&nbsp; Storing an single&nbsp;index isn't going to tax your server, plus you really won't need to worry about Session timeouts or whatnot for something like this.</p> <p>-Damien</p> 2007-10-06T01:28:15-04:002582745http://forums.asp.net/p/1164172/2582745.aspx/1?Re+Maintaining+Accordion+panel+selected+state+across+postbacksRe: Maintaining Accordion panel selected state across postbacks <p>hi i have tried all the solutions provided this forums and other forms but nothing woks</p> <p>because when u are redirecting the page it actually calls the get method not the post method.</p> <p>so accordain can not maintain its seleted pane.</p> <p>to do so you have to store the acordain seleted index in session and programaticaaly set the index of accordain during postbacks/</p> 2008-08-27T08:12:54-04:00