views:

255

answers:

1

I'm dynamically binding tables and sub tables using nested listviews. On the client side I have a piece of jQuery that is toggling the visiblity of TRs witin the tables in order to provide a group expand / contract view option.

On postback I'm obviously loosing my class changes that I have applied via jQuery. I'm wondering what the best approach to maintaining these client side class changes is? I've considered creating a hidden input control per table to store the indexes of the visible TRs at the time of expanding them. The intention being to then look for the indexes during postback / rebinding and add the visible classes to each corresponding element.

Is there a better approach or some native method of passing back the client side style / class change to the server during postbacks?

+2  A: 

There are a number of ways to do this:

  • As you suggest, a hidden control that contains infomation about changes to view state, the server side then uses this information to render correctly the next time, or the javascript looks at this information on page load and adjusts the page. If you want the data to persist across sessions (log ins) then you need to have the server side store the info in the DB and render it on every page access.
  • If you want the data persist then it is sometimes better to have an ajax call to store the information on the server when a change is made. This has the advantage of not forcing the user to submit the form in order for the changes to be persisted. If the page you are working on does often get submitted (or maybe does not even have other form elements) this is probably the better option.
  • Old school: store the information in a cookie. Blah, no one does this anymore.
Hogan