Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i am facing an issue, which i have mentioned below.
How to redirect to error page on exception via global.asax when button in the update panel is clicked?

Could you please respond to this.

Thanks,
Prasad
Posted

1 solution

When your application throw error, then 'Application_Error' event will occur in global.asax
in that you can use 'Server.GetLastError()' method to get last error occurred, here you can get 'InnerException' and redirect to error page
see below snippet

Global.asax

  void Application_Error(object sender, EventArgs e) 
     {    
         Exception err = Server.GetLastError();
         Session["error"] = err.InnerException.Message;    
    }
     void Session_Start(object sender, EventArgs e) 
     {      
         Session["error"] = "";//initialize the session
    }

//in web.config

 <customErrors mode="On" defaultRedirect="Error.aspx"></customErrors>

//In Error.aspx.cs access the error and show it on form

  protected void Page_Load(object sender, EventArgs e)
     {
         if (Session["error"] != null)
         {
             Response.Write(Session["error"].ToString());
         }
    }

hope it helps
 
Share this answer
 
Comments
Prasadsm 15-May-14 9:33am    
Thanks for the Info Prasad,

but in my case, i am redirecting to the "Error" page in Application_Error method,
and Web.config i have set <customerrors mode="Off">. Instead of defaultRedirect we are handling it manually. The "Error" page gets executed but won't be redirected.

I am getting the below error message saying,

JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
koolprasad2003 16-May-14 3:49am    
may be following link will help you more to accomplish your task
http://dotnetdebug.net/2006/12/28/syswebformspagerequestmanagerparsererrorexception/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900