Getting values from viewstate using JQuery?

99封情书 提交于 2019-11-30 16:06:50

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1050902/getting-values-from-viewstate-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!