使用動態數據時,為什麼我的視圖狀態在回發之間增長? (Why is my viewstate growing between postbacks when using dynamic data?)


問題描述

使用動態數據時,為什麼我的視圖狀態在回發之間增長? (Why is my viewstate growing between postbacks when using dynamic data?)

I'm writing a pretty complex web form using ASP.NET Dynamic Data.  Several of the controls on this form post back, since there are dependencies between controls.  I'm noticing that the viewstate is growing larger with every postback, until after 5 or so there is a long delay between the Render process and the page actually loading in the web browser.  

This occurs even if I'm JUST clicking a radio button to cause the postback, without entering any data or any other changes into the form...

I checked the older version of the form, which does not use Dynamic Data, and the viewstate doesn't grow at all... so I'm theorizing that the dynamic data controls are somehow to blame...

Anyone else seen this?  Is there a fix for it?


參考解法

方法 1:

I don't know the direct answer to your question, but perhaps one of these tools may help you diagnose further:

(1) Fritz Onion's ViewState Decoder tool might be able to help you figure out what's getting stuffed in there.  You can find ViewSate Decoder listed at the Pluralsight Tools page.  Direct download link: ViewStateDecoder22.zip.

ViewState Decoder screen shot http://alt.pluralsight.com/images/decoderscreenshot.gif

(2) Another tool that may be worth looking at is ASP.NET ViewState Helper:

  

"[...] ASP.NET ViewState Helper is   designed to help all web developers,   but has specific features to help   ASP.NET developers debug ViewState   issues. Analyze your web pages in   real-time while you browse them using   Internet Explorer 6.0 or higher.   [...]"

方法 2:

Ok, so the culprit was Telerik's RadComboBox.  More specifically, it was the lack of support for Dynamic Data using RadComboBox.  To be even MORE specific:

The workaround for using a RadComboBox with DynamicData is to have a DropDownList with visible set to false, call the PopulateListControl on that DDL and then copy the items to RadComboBox.

This works fine, except when you do that on every postback... I'm guessing it stuffs the entire list into Viewstate when you do it that way, and since I was doing it every postback... the viewstate kept growing.

(by CodeRedickChris W. ReaCodeRedick)

參考文件

  1. Why is my viewstate growing between postbacks when using dynamic data? (CC BY-SA 3.0/4.0)

#ASP.NET #asp.net-3.5 #dynamic-data #asp.net-dynamic-data #viewstate






相關問題

System.Reflection.Assembly.LoadFile 鎖定文件 (System.Reflection.Assembly.LoadFile Locks File)

如何在沒有全局變量的情況下一直保留我的變量? (How can I keep my variable all the time without global variables?)

C# / ASP.NET - Web 應用程序鎖定 (C# / ASP.NET - Web Application locking)

關閉模態對話框窗口後 ASP.NET 刷新父頁面 (ASP.NET Refresh Parent Page after Closing Modal Dialog Window)

無法將 NULL 值傳遞給數據庫 (Unable to pass NULL value to database)

wcf:將用戶名添加到消息頭是否安全? (wcf: adding username to the message header is this secure?)

使用 ASP.Net 教初學者 Web 開發的小項目想法 (Small projects ideas to teach beginners web development using ASP.Net)

SQL Server - 分組、擁有和計數 (SQL Server - Group by, having and count in a mix)

企業庫異常處理應用程序塊和日誌記錄應用程序塊在 ASP.NET 中的正確使用 (Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET)

來自proc的asp.net多個結果集:是否有必要將結果映射到類?如果是這樣,怎麼做? (asp.net multiple result set from proc: is it necessary to map results to class? If so, how?)

如何在測試工具中實例化 asp.net 代碼隱藏類? (How can I instantiate an asp.net codebehind class in a test harness?)

Web 窗體用戶控制事件,需要在頁面加載後添加 (Web Form User Control Event, needs to be added after page loads)







留言討論