如何在Asp.Net中使用Jquery清除Viewstate属性? [英] How Can I Clear Viewstate Property Using Jquery In Asp.Net?

查看:174
本文介绍了如何在Asp.Net中使用Jquery清除Viewstate属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.NET中使用jQuery将ViewState ["Drivers"]设置为null?

How can i set ViewState["Drivers"] to null using jQuery in ASP.NET ?

ViewState["Drivers"]= null;

推荐答案

您应该知道ViewState(以及其他MVC的对象)是服务器端的,并且在运行时进行操作后,将内容(以HTML形式)发送到客户端后,就不再与这些对象建立连接.然后,要操作DOM,您必须使用JavaScript(或jQuery),然后更改HTML内容的状态.

要更改该值,您需要向服务器发出另一个请求(通常使用QueryString来告知服务器您要更改该值或要执行某些操作,而不仅仅是获取值或静态HTML页面). jQuery允许您创建一个ajax请求.您可以将此请求发送到服务器,并处理该请求(在控制器内部)以更改ViewState.

You should know that ViewState (and other MVC''s objects) are server-side and are manipulated on the run-time, after the content is sent (in HTML form) to the client, there is no connection to those objects anymore. To manipulate the DOM then, you have to use JavaScript (or jQuery specifically) and you alter the state of HTML content.

To change the value, you make another request to the server (generally with a QueryString to tell the server that you want to change the value or you want to do something instead of just getting the values or static HTML page). jQuery allows you to create an ajax request. You can send this request, to the server, and handle the request (inside the controller) to change the ViewState.


(文档).ready(函数(){
(document).ready(function () {


.ajax({ 网址:' 您的控制器/update_viewstate', 成功:功能(数据){ // 值已更改.. } }); });
.ajax({ url: 'your_controller/update_viewstate', success: function (data) { // value altered.. } }); });



现在,在服务器端的update_viewstate动作中,您可以根据需要(在帖子内部)更改ViewState.然后,您也必须更改View,因为View的依赖项已更改,依此类推.所以我想说,这是改变视图属性的la脚方法.您可以根据需要简单地更改HTML内容.



Now, on the server-side inside the update_viewstate action, you can change the ViewState as you want it (inside your post). Then you will have to change the View too, because View''s dependencies have been altered and so on. So I would say, this is a lame method to alter the View''s properties. You can simply change the HTML content if you have to.


这篇关于如何在Asp.Net中使用Jquery清除Viewstate属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆