When a SQLDatasource (or other DataSource Control) fail on a SQL operation a exception is fired like: duplicate key exception
user should not see the plain exception message. Goal is to display a custom message in validation summary. My case use a formview control and a sqldatasource for inserting. I hook into the Inserted Event and cancel the exception. A Customvalidator exists on page for error handling and is set to isvalid=false.
Protected Sub SQLDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) If Not IsNothing(e.Exception) Then e.ExceptionHandled = True
CustomValidator1.IsValid =
False End Sub Most posts which i found by search engine are meaning that this is not possible. Partial true. The trick is that the Validationsummary and the Customvalidator must be placed outside the Formview, which works fine also for the other inside validation controls.
<asp:CustomValidator ID="CustomValidator1" Display=none runat="server" ErrorMessage="Email Adresse bereits vorhanden" > </asp:CustomValidator> So easy!