Getting values from viewstate using JQuery?

Is it possible to get a particular value out of viewstate using JQuery….

I’m working on a custom control. It uses jquery, embedded into the control itself to manipulate the value in a text box… I need to implement a minimum and maximum values… the properties are set up in the control, and are stored in viewstate… Instead of using hidden input fields, i’d much rather just pull the info out of viewstate and use it that way…. is it at all possible?

Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The short answer is that you can do it under some circumstances, but it really isn’t a good idea.

If you are writing the control for others to use, there’s no way ViewState is going to work. By default, ViewState is Base64 encoded which is easy enough to decode, but users of your control may want to encrypt their ViewState data, in which case you would be hosed.

If you are writing the control for your own consumption and you only need to read from ViewState, you could do so, but I wouldn’t recommend it unless you find a well-debugged library to parse it for you. The format is a bit hairy (see ViewState: All You Wanted to Know and Understanding ASP.NET ViewState for more details).

As you mentioned, using a standard hidden field is a fine alternative, or you could inject another block of javascript into your page to set the variable values at whatever point the control sets them.

Method 2

You could also output the min and max as custom attributes of the textbox (and even namespace them if you want to retain xhtml validity); then you’d reference them as $thebox.attr('min') and $thebox.attr('max') or similar.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x