I have a GridView that is inside of an UpdatePanel. I am using the RowCommand event to insert data, but currently if an exception is thrown, it is not being written to the trace like I want. Is there a way I can output the exception message when using the asynchronous postback?
Wrap your method that is running the async code in a try catch, write the error to trace in the catch.
If it is not hitting the code, then are you handling the right Gridview Event? For example if you have a button with a delete command, but are handling the code in the GridViewCommand and do not handle the Event GridViewDeleted it would throw an exception.
During asynchronous postbacks, the exceptions are not sent to the client, instead the ASP.NET ajax mechanism handles the errors. Whenever an unhandled exception occurs on the server side, an alert
message-box will be shown to the user containing the exception message. To handle it in your own way, you can tap into PageManager's EndRequest event like this -
Sys.Application.add_init(__AppInit);
var __pageManager;
function __AppInit() {
__pageManager = Sys.WebForms.PageRequestManager.getInstance();
__pageManager.add_endRequest(__EndRequest);
}
function __EndRequest(sender, args) {
var error = args.get_error();
if (null != error) {
args.set_errorHandled(false);
}
}
I've struggled with something like this before. If, in your ScriptManager tag, you turn off Partial Page Rendering,
<asp:ScriptManager runat="server" id="ScriptManager"
EnablePartialRendering="false" />
you should then see the ASP.NET YSOD which should enable you to diagnose the problem. Turn partial rendering back on once you've fixed it.