Viewstate not preserved when handling exception, ASP.NET

orfeo087

New Member
I'm using a detailsview for a dialog to the user, and it seems that the viewstate is not preserved when there is an error inserting the data.I'm using a OnInserted handler on the datasource to check if there was an exception like so:\[code\]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; } }\[/code\]Which simply calls the client side JS function:\[code\]function showError(overlayName) { $(".msgError").css('visibility', 'visible'); $(overlayName).css('visibility', 'visible');}\[/code\]My detailsview looks something like this:\[code\]<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>\[/code\]It all works fine, but for some reason the ASP viewstate is not preserved. Meaning that if I fill out incorrect information in the form and submit I will get the appropriate error and the dialog will still be displayed. But the fields are not filled out with my old values.If someone could give me some pointers or help me out I'd greatly appreciate itKind regards
 
Back
Top