ASP.NET 動態建立控制項引起的ViewState讀取問題

來源:互聯網
上載者:User
今天在開發ASP.NET上的控制項時遇到了一個鬱悶的問題,頁面上有一個View Switch的功能要實現,可以選擇使用Chart或是Grid來查看資料,包含了Grid Only, Chart Only, Grid with Chart等幾種布局。開始的時候發現由Grid at Bottom到Grid at Right切換的時候,Chart的View State始終是null,後來實現Grid only到Grid at Right時,出現了以下的錯誤。

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

Stack Trace:

[HttpException (0x80004005): Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.]   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +189   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +414   System.Web.UI.Control.AddedControl(Control control, Int32 index) +291   System.Web.UI.ControlCollection.Add(Control child) +153   USoft.Aurora.WebControls.AnalysisReport.CreateChildControls() in e:\project\aurora\code.v6\aurora\analysiswebcontrols\analysisreport.cs:172   System.Web.UI.Control.EnsureChildControls() +100   System.Web.UI.Control.PreRenderRecursiveInternal() +38   System.Web.UI.Control.PreRenderRecursiveInternal() +125   System.Web.UI.Control.PreRenderRecursiveInternal() +125   System.Web.UI.Page.ProcessRequestMain() +1499

出錯資訊倒也詳細,一看就知道出錯原因,可是沒想到Web Controls上還有這樣的要求。

問題已經解決,但暫時不貼上來了,希望能聽聽大家的意見。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.