protected void formviewEditClient_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { bool hasErrors = false; SqlException sqlexception; if(e.Exception != null) { hasErrors = true; if(e.Exception.InnerException.GetType() == typeof(SqlException)) { sqlexception = (SqlException)e.Exception.InnerException; switch(sqlexception.Number) { case 2627: { Label lb = (Label)this.formviewEditClient.FindControl("labelTester"); lb.Text = "Testing of internal."; CustomValidator cv = (CustomValidator)this.formviewEditClient.FindControl("CustomValidator2"); cv.IsValid = false; e.ExceptionHandled = true; e.KeepInEditMode = true; break; } } } } if(!hasErrors) { Response.Redirect("~/WebForms/Main.aspx"); }