简体   繁体   English

ASP.Net ValidationSummary控件不显示异常

[英]ASP.Net ValidationSummary control doesn't show exceptions‎

I have asp.net page with the following markup: 我有带有以下标记的asp.net页:

<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. 当用户按下按钮保存时,我的自定义命令处理程序将调用SubmitChanges并将数据从网格保存到数据库。 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 . 所有数据库异常都作为包装在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. 因此,我期望例外文本将在ValidationSummary为带有例外消息的标签,但是我的应用崩溃了,并且看到了应用错误页面。
So, how to handle ValidationException from database layer and display exception message in ValidationSummary control without app crashing? 那么,如何从数据库层处理ValidationException并在ValidationSummary控件中显示异常消息而不会导致应用崩溃? 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. 嗨,将您的代码块放入try catch中,如果发生异常,则弹出显示模型以显示错误。 Just use ModelPopUp.show() method to display model pop up in code behind in catch block. 只需使用ModelPopUp.show()方法来显示在catch块后面的代码中弹出的模型。 Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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