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
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.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 theirViewState
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.