I'm trying to handle errors which occure when a user tries to do a CRUD functionality. For example when he leaves an input field open which can't be NULL in the database.
When I run my website and leave an input field open, this happens:

When I stop running and go back to that specific page, it DOES show the label I want(red font = error message to the user):

So at this point: It does show the error message I intended, but only after it crashed.
My code:
// ERROR HANDLING ODSTYPES
protected void odsTypes_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Dit type kan niet worden verwijderd.";
}
e.ExceptionHandled = true;
}
protected void odsTypes_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Er ging iets fout bij het updaten van het type. Probeer opnieuw.";
}
e.ExceptionHandled = true;
}
protected void odsTypes_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Er ging iets fout bij het invoeren van het type. Probeer opnieuw.";
}
e.ExceptionHandled = true;
}
// ERROR HANDLING DTVTYPES
protected void dtvTypes_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Er liep iets fout! Mogelijk gaf u een verkeerde waarde op. Probeer opnieuw.";
}
e.ExceptionHandled = true;
}
// ERROR HANDLING GVTYPES
protected void gvTypes_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Dit type kan niet worden verwijderd.";
}
e.ExceptionHandled = true;
}
protected void gvTypes_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
{
lblError.Visible = true;
lblError.Text = "Er liet iets fout, mogelijk gaf u een verkeerde waarde in. Probeer opnieuw";
}
e.ExceptionHandled = true;
}
