简体   繁体   中英

ASP.Net ValidationSummary control doesn't show exceptions‎

I have asp.net page with the following markup:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <asp:ValidationSummary ID="validationSummary" runat="server" EnableClientScript="true" HeaderText="Errors list:" />
    <asp:DynamicValidator runat="server" ID="gridViewValidator" ControlToValidate="gridView" Display="None" />
    <asp:GridView ID="gridView" runat="server" DataSourceID="GridDataSource" OnRowCommand="gridView_RowCommand">
      <Columns>
        <asp:DynamicField DataField="column1" />
        <asp:DynamicField DataField="column1" /> 
        <asp:DynamicField DataField="column1" /> 
        <asp:Button ID="btnSave" Text="Save" runat="server" CommandName="CustomSave" CausesValidation="true" />
      </Columns>
    </asp:GridView>
    <asp:DynamicLinqDataSource ID="dynamicLinqDataSource" runat="server" />
  </ContentTemplate>
</asp:UpdatePanel>

When user press button save my custom command handler invoke SubmitChanges and save data from grid to database. Sometimes (for example check constraint is broken) save is fails and exception is trows. All database exception is throw to higher level as database exception that wrapped into ValidationException .
So, I've expect that exception text will be shown in ValidationSummary as label with exception message, but my app is crashes and I see app error page.
So, how to handle ValidationException from database layer and display exception message in ValidationSummary control without app crashing? May some additional configuration is needed?

Hi, Put your code block in try catch and if exception occurs show model pop up to display errors. Just use ModelPopUp.show() method to display model pop up in code behind in catch block. Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM