Reputation: 107
I used regular button to throw span into button. I also made onServerClick function (to handle the event).
<button id="btnCancel" runat="server" class="btn btn-default pull-right" onserverclick="btnCancel_Click"><span class="glyphicon glyphicon-remove text-magenta"></span>Cancel</button>
This should be simple cancel button that should exit the form and noting else. But for some reason C# function throws exception on redirect.
Here is the function:
try
{
Response.Redirect("StartPage.aspx");
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
Response.Redirect("Error.aspx", false);
}
Also if I just dont put try and catch block everything works fine.
Upvotes: 0
Views: 163
Reputation: 22456
Response.Redirect
throws a ThreadAbortException
that is caught by your exception handler. Either
Response.Redirect
out of the exception handler orThreadAbortException
like this:try
{
Response.Redirect("StartPage.aspx");
}
catch (ThreadAbortException)
{
// Exception is expected, do nothing
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
Response.Redirect("Error.aspx", false);
}
Upvotes: 1