我使用jQuery和ASP.NET來顯示包含按鈕的對話框。經過一番淘汰之後,我通過添加更多JavaScript來將對話框添加到表單中,從而使對話框中的按鈕發揮作用。ASP.NET操作DOM時的ViewState驗證
var dlg = $('#ctl00_ctl00_PageContent_PageContent__pnlPopup').dialog({
autoOpen: false,
height: 180,
width: 500,
modal: true,
draggable: true
});
dlg.parent().appendTo($('form:first')); // without this, controls in the dialog are non-functional
,直到我打開的對話框中能正常工作,將其關閉,然後嘗試使用像父頁面上具有ComboBox或LinkButton的控制。在這一點,我收到了ViewState的驗證錯誤:
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.
有沒有解決這個辦法嗎?我看到爲什麼會發生這種情況 - jQuery正在改變文檔的結構,但我不完全確定這是如何/爲什麼會影響ViewState。
您是否找到解決方案?我有類似的問題。 – earthling