English 中文(简体)
查阅关于美国退休人员协会电话的国家信息
原标题:Limiting view state information on AJAX calls

我在同一个网页上有一个入境表和一个GridView。 GridView选择了一行,上面表格中文本Boxes与GredView浏览的所有条目一起。

当该网页开放时,如果从GredView中选取任何一行,我可以看到许多观察国的数据被发送到服务器,同时附上美国宇宙航空研究开发机构的请求。 我选择了浏览器的源选择,以加以核对。 我利用:EnableViewState = “false”,试图在网页上抹去观察国,但我的申请却停止正确进行。

在从GredView中选取任何一行时,会产生错误,因此,我重新接纳了意见国。

是否有最优化的办法来利用观察国,使非洲复兴开发银行的要求少? 任何与观察国压缩有关的内容?

I am using ASP.NET 2.0.

最佳回答

从您使用<代码>UpdatePanel时起,在盒式中,你用“发送所有表格,包括大观点国家。

你有两种办法,一种是使习惯化,ajax呼唤,只注重你们控制的变化,而不是更新小组的全部后退。

The other way is to minimize what page send back with each post back, and compress the viewstate.

To compress the viewstate I suggest some pages here that have ready to use source code.

http://www.codeproject.com/Articles/14733/ViewState-Compression

http://www.hanselman.com/blog/ZippingCompressingViewStateInASPNET.aspx

http://www.bloggingdeveloper.com/post/How-To-Compress-ViewState-in-ASPNET-20-ViewState-Compression-with-SystemIOCompression.aspx

and a similar question that I did: How to limit the number of post values on UpdatePanel?

问题回答

首先,如果你重新使用更新小组的话。 它效率不高。 实际上,它完全是后退,你显然试图回避。

Why not use a GET AJAX request? This will not post anything to the server, other than the URL your passing which could include the Id of the row you need?

基本:

建立一个网络服务,将满足你们需要的数据。

在电网各行各处向特顿进行电击活动。 (在约束性事件服务器方面最容易做的,使用约束性物体接上电线)

活动称为上述网站服务(http://api.jquery.com/jQuery.get/)。

在“javascript”活动的附带方法中,该条目按要求建立。

我同意Kevin M和Aristos。 另一种方式是,如何尽量减少转移的“观点”规模:利用习俗观察国的提供者将其储存在服务器上。 本条描述了如何创建这种供应商:。 http://www.codeproject.com/Articles/8001/ViewState-Provider-an-implementation-using-Provide

使用习俗观察家产生哪些陷阱?

As stated in all posts, you can do some form of compression in multiple ways, you can implement it yourself or buy a viewstate compressor, but that won t help you too much. What might be interesting is the amount of compression you should expect. Take a look at: RadCompression to gets some info on compression rates, and performance improvements that are generally the same for all choices (free/paid).

我认为,这一比率并不令人满意,你应寻找办法解决你的问题。

Now, if I understand correctly you want to edit a grid row in a form on the same page. From the comments, you are using an update panel, and by the behavior described you have both your grid and edit form in an update panel. If your page has only the grid and edit form, having them in an update panel won t help at all.

I ve made a small example for test purpose and I had a 10 rows grid with 5 columns and an edit form for the 5 fields on the same page. My observations are:

  1. Having a grid with no style got me a 1500 char viewstate that amounts to 2KB. Adding styling would get you to a lot more data in viewstate, you can check any paid grid control examples and see that the amount of uncompressed viewstate goes on and on for hundreds of rows.
  2. Postbacking the hole page (no update panel) on grid selected item made a request of 3KB and got a response of 6KB
  3. Postbacking using an update panel that surrounds the grid and edit form made a request of 3KB and got a response of aprox 6KB. Almost no change in content size.

这是因为,利用更新小组,基本上意味着你不会更新整个网页,而只是你更新的Ppanel + 视带内的区域。 因此,如果更新小组包围了你的所有网页,那就赢得了你们的帮助,而且说它是不公平的。

Now, asp.net web forms has it s strengths but my opinion is that nobody likes asp.net web forms anymore, especially when having asp.net mvc / wcf / jquery at hand. Your question proves one of the limitations of asp.net web forms when used as originally intended.

My general solution for your problem would be:

  1. Use html only controls for data display (your grid should be a jquery/extjs plugin that displays json data that you get from an WCF ajax enabled web service). Getting rid of the asp grid will help you lower viewstate to almost nothing and make your page source readable.
  2. Make a WCF Ajax Web Service and exchange json in the client <-> wcf relation (examples of methods to use are: getgriddata, addnewrow, deleterow, editrow). Having these methods in place means that you won t have to fully postback at all, and that will make your page even nicer and more responsive. Also I would try not to use any code in page events.
  3. Call your web service using jquery or other javascript framework that you prefer; making sure you do not use the dreadful asp:ScriptManager will help you get rid of multiple calls to /ScriptResource.axd? and some odd looking in source javascript that does some wiring.

答案是没有的。

Here is a way to free page from clutches of viewstate on ajax calls

  • Do not depend on the row click event of the grid view.
  • Add a link column to the grid view. Do not use server click event.
  • link When user clicks the link make an ajax call by sending the id of the row. You will be using a jQuery to make an ajax get call.
  • Once the ajax call returns, take the data of the record and find the form elements, again using jQuery and populate them




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签