使用 jQuery 更新 ViewState
我开始更频繁地使用 jQuery,尤其是 jQuery 中的 .ajax()。我想知道使用 .ajax() 操作 ViewState 是否是一个好主意,或者是否有更好的方法来操作 ViewState 而无需完全回发。
I started to use jQuery more intensively and especially .ajax() in jQuery. I would like to know if it is a good idea to manipulate ViewState using .ajax() or if there is a better way to manipulate ViewState without a full postback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会说不。除了您必须处理编码字符串这一事实之外,任何错误都会导致整页回发失败。
如果您需要在回发期间将 ajax 查询结果的数据传递回服务器,我建议将其存储在一个或多个隐藏字段中,并从服务器上的表单集合中检索它们。
I would say no. Apart from the fact that you will be having to deal with an encoded string, any error would result in a full page post back failing.
If you need to pass data that was the result of ajax queries back to the server during a postback I would suggest storing it in a hidden field or fields and retrieving them from the form collection on the server.
除非你有非常具体的理由并且知道自己在做什么,否则这听起来像是一种会让你陷入很多痛苦的方法。 ViewState 不应该由客户端修改。
你为什么要这样做?我猜想有一种更简单、更易于维护的方法来实现您想要实现的目标。
Unless you have a very specific reason and know what you are doing, this sounds like an approach that will lead you into a lot of pain. ViewState isn't meant to be modified by the client.
Why would you want to do this? I would guess that there is an easier and more maintainable way of achieving what you are trying to achieve.