Reputation: 32390
I've written a user control that has a button that a user can click to display an additional DIV. I discovered that it would be nice to make the control remember whether or not the DIV is visible after postback so that when the page reloads, the DIV stays visible if the user wants it that way.
What is a good way to implement this with jQuery at my disposal?
Upvotes: 2
Views: 158
Reputation: 88064
There are several ways to do this:
Use Viewstate. @Oded has a good article on it.
Use a hidden field. Just have your button write a value to the field such as "true" when clicked. You can check the value of that field on post backs.
Use a cookie.
==============
If the show/hide logic is completely happening on the client side then I'd probably just have my user control put a hidden field and let the javascript check that field for a value when the page loads.
Upvotes: 1
Reputation: 1406
To stay in jQuery land, I'd use a cookie. I've used this cookie plugin in several projects:
https://github.com/carhartl/jquery-cookie
Upvotes: 1