Put a
break point[
^] in the
catch
block and see what is the actual error message and try to correct it.
catch (Exception ex)
{
HttpResponse.Redirect Method [
^] is used to navigate to other page, it accepts the
url
as the argument, where as you have passing the exception error message, so the method will look for the page (url) which is not there eg,
Response.Redirect("object reference not set to an instance");
It should look something like
Response.Redirect("SomePage.aspx")
You shall show the error message in following ways,
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('"+ex.Message+"');", true);
}
or
Add a label control to your page and show the error information in the label as
Label1.Text = ex.Message;
or
Create an error page and load the information from query string as
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Text = Request.QueryString["Message"];
}
using
catch (Exception ex)
{
Response.Redirect("ErrorPage.aspx?Message=" + ex.Message);
}