Reputation: 654
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;
}
Upvotes: 0
Views: 64
Reputation: 66449
What you're experiencing is just a Visual Studio feature, where it breaks on Exceptions.
To disable it, click on Debug in the menu, and choose Exceptions.
From there, uncheck "Common Language Runtime Exceptions" in order to stop Visual Studio from breaking on exceptions:
Upvotes: 1