1
我正在爲用戶使用對話框的細節視圖,而且在插入數據時出現錯誤時,視圖狀態似乎不會保留。視圖狀態在處理異常時不保留
我使用的數據源一個OnInserted處理程序,以檢查是否有異常,像這樣:
protected void areaInsertHandler(Object sender, SqlDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
// There was an error in submitting, show the error dialog
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "DialogHandler", "showError('#overlayAreas');", true);
e.ExceptionHandled = true;
}
}
它只是調用客戶端的JS函數:
function showError(overlayName) {
$(".msgError").css('visibility', 'visible');
$(overlayName).css('visibility', 'visible');
}
我的長相的DetailsView這樣的事情:
<asp:UpdatePanel ID="AreaUP" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="overlayAreas" class="overlay">
<asp:DetailsView
ID="DetailsView_Areas"
runat="server"
Visible="True"
AutoGenerateInsertButton="False"
AutoGenerateRows="False"
caption="<a style='font-weight: bold;'>Bold</a> = Required field"
CaptionAlign="Bottom"
headertext="Create new area"
EnableViewState="true"
DataKeyNames="Area_Name"
DataSourceID="AreasSource"
DefaultMode="Insert">
<Fields>
...
</Fields>
</asp:DetailsView>
</div>
<br />
<asp:Button width="200" height="30" ID="Button_CreateArea" runat="server" OnClientClick="return btnToggle('#overlayAreas')" Text="Create new area" />
</ContentTemplate>
</asp:UpdatePanel>
這一切工作正常,但由於某種原因ASP v iew狀態不會保留。這意味着如果我在表格中填寫不正確的信息並提交,我會得到相應的錯誤,對話框仍然會顯示。但是這些領域並沒有被我的舊價值所填補。
如果有人可以給我一些指點或幫助我,我會非常感激
編輯10-08:仍然沒有能夠解決它,任何想法呢?
難道是您使用的是ASP.NET框架的舊版本,如果在頁面,用戶控件和母版頁聲明中設置enableviewstate不能在頁面上的控件中重寫? –
@TorAndersson,不要這麼想,我的目標是.NET框架4 – ChewToy