今天在開發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上還有這樣的要求。
問題已經解決,但暫時不貼上來了,希望能聽聽大家的意見。