I do some custom Validation in the OnInserting-Event of a data-binded DetailsView and cancel when needed the operation.
Now i want to give the user a feedback, why the Insert is not operated and tried a lot of stuff like Custom-Message-Boxes, making Labels visible and so on.
But no Code is doing something like usual in that event. Before or after the line with the cancelling (e.cancel = true). The code is debugging without errors but without any effect.
Am i going the wrong way? What is the usual workflow for something like that?
I hope somebody can tell me what I'm doing wrong.
(The related part what is not executing is below "// THIS PART:")
protected void DetailsView2_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
// E-Mail auf Existenz prüfen, wenn existiert abbrechen und Nachricht
string email = e.Values["email"].ToString();
int vorkommenDB = 0;
string abfrage = "select count(*) from [user] where email = @mail";
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringLOKALverband"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(abfrage, con))
{
command.Parameters.AddWithValue("@mail", email);
con.Open();
int.TryParse(command.ExecuteScalar().ToString(), out vorkommenDB);
con.Close();
}
}
if(vorkommenDB > 0)
{
// THIS PART:
myMessageBox.Show("Die E-Mail Adresse existiert schon in der Benutzer-Datenbank.\r\nBitte bearbeiten Sie den Datensatz mit der vorhandenen Adresse und legen ihn nicht neu an.");
Label temp = (Label)((DetailsView)sender).FindControl("labelEmailDoppelt");
temp.Visible = true;
Response.Redirect("user.aspx?email=belegt");
e.Cancel = true;
}
// Passwort verschlüsseln und Parameter ersetzen
if (e.Values["passwort"] != null)
{
string passwortInsert = e.Values["passwort"].ToString();
string hashVonPasswort = mySHA1.SHA1HashStringForUTF8String(passwortInsert);
e.Values["passwort"] = hashVonPasswort;
}
}