Getting values from viewstate using JQuery?

試著忘記壹切 提交于 2019-11-30 15:56:56

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

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