0

I have a ajaxToolkit:CollapsiblePanelExtender along with two asp:UpdatePanels it controls (one panel expands the other panel when clicked).

Works great until I do an AJAX update from a Timer that kicks off. The page updates...and the CollapsiblePanelExtender collapses :-P

Anyone know how to get this control to maintain the state of the panel it's expanding?

kenyee
  • 2,309
  • 1
  • 24
  • 32

2 Answers2

3

I remember running into this exact problem.

CollapsiblePanelExtender has a property, ClientState, that doesn't seem to get tracked and maintained in ViewState.

You should be able to manually track and maintain the value in a HiddenField (or ViewState or Session, if you like) and restore the CPE.ClientState to that value upon the AJAX update.

UPDATE
Found a resource that suggests that you simply need to set both Collapsed and ClientState properties. http://weblogs.asp.net/ashicmahtab/archive/2008/11/21/act-collapsiblepanelextender-how-to-collapse-expand-programmatically.aspx

wonkim00
  • 637
  • 3
  • 9
  • That's horrible...it basically means there's a bug in the control so it doesn't maintain Viewstate. I thought about doing something similar using a jQuery panel instead if the CPE control doesn't work that well :-P – kenyee Nov 14 '11 at 03:10
  • FWIW, I ended up using jquery to grab the state changes and update a hidden field that was then passed back in the ajax POST, then the code would decode the field (a CSV list of expanded sections) and set clientstate appropriately). Major hack for something that should be fixed in asp.net IMHO... – kenyee Jan 23 '12 at 17:11
0

I've run into this in another circumstance...

  1. Panel is collapsed Timer ticks, and a partial postback begins
  2. User expands panel while postback is in progress
  3. Partial postback ends, and the state of the panel is returned to "collapsed" because viewstate is maintained - it's just returned to where it was at the beginning of the partial postback.

How you want to handle this depends on your circumstance, but in my case I cancel the asynchronous postback when the user expands or collapses a panel. Since it's a timer updating current values every few seconds, it will just run again soon anyway so I'm able to "lose" one.

Alternately, you could disable expand/collapse functionality for the duration of the postback by using the panel's add_expanding and add_collapsing events, and checking Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack().

msulis
  • 555
  • 5
  • 17