天天看點

程式運作出現錯誤:System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded

近日在使用ArcGIS Server列印出圖時,在列印完成後,關閉操作面闆Pannel時,頁面上總是提示:

System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)

   在 System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()

   在 System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)

   在 System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument)

   在 System.Web.UI.WebControls.RadioButtonList.LoadPostData(String postDataKey, NameValueCollection postCollection)

   在 System.Web.UI.WebControls.RadioButtonList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)

   在 System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)

   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

查找到的原因是:

      應該是因為asp.net2.0預設以EnableEventValidateion驗證, 是以當你的程式以用戶端腳本進行postback或向前台輸出html标記時,可能會引發類似的驗證異常,回發或回調參數無效。在配置中使用 <pages enableEventValidation="true"/> 或在頁面中使用 <%@ Page EnableEventValidation="true" %> 啟用了事件驗證。出于安全目的,此功能驗證回發或回調事件的參數是否來源于最初呈現這些事件的伺服器控件。如果資料有效并且是預期的,則使用 ClientScriptManager.RegisterForEventValidation 方法來注冊回發或回調資料以進行驗證。

解決辦法:

      在頁面的<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 中添加 EnableEventValidation="false" 就可以了。