Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Luis Abreu is an ASP.NET MVP who has a great blog on the http://msmvps.com blog site.  Earlier today he posted a great tutorial post that describes how to use some of the new features in the ASP.NET AJAX Beta1 release to add more robust error handling into your application.  I highly recommend reading and bookmarking it for future use.

Error handling in an AJAX world can often be tricky -- especially when AJAX call-backs are taking place and a mixture of client and server code is running within an application.  In its most recent release, the <asp:updatepanel> control that comes with ASP.NET AJAX now has much more robust error handling and reporting features for you to use.  Specifically:

1) You can now handle the "OnAsyncPostBackError" event on the <asp:scriptmanager> control to catch and/or modify an error message that occurs during the processing of an AJAX postback callback on the server. 

2) You can now set the "AllowCustomErrors" property on the <asp:scriptmanager> control to enable the standard ASP.NET custom error support to be enabled to redirect a user automatically to an error page when an error occurs (even if it is happening during an AJAX postback).

3) You can now optionally handle client-side JavaScript events on the page to intercept any error message sent back from the server, and perform custom client-side actions as a result (for example: to output the error message to a nicely formatted <div> section instead of performing a pop-up message). 

Read all about how to take advantage of the above new features from Luis' great tutorial here.

Hope this helps,

Scott

Published Sunday, October 29, 2006 6:56 PM by ScottGu

Comments

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, October 30, 2006 4:22 AM by vikram
great link to a good post. Till now I used to see the JavaScript alert box in time of errors

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, October 30, 2006 12:51 PM by Ryan Ternier
Great post, thanks Scott! Saves our team tons of time figure out how to do this :D

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, October 31, 2006 10:14 AM by ScottGu

Hi Daniel,

Can you send me an email with more details on this (scottgu@microsoft.com)?  I will then loop you in with some folks on the ASP.NET AJAX team to help investigate and figure out what is going wrong.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Wednesday, November 1, 2006 12:21 AM by Caleb
Wow Scott, do you sleep sometime? I'm looking at your posts, and the hours you post it, I think you drink a lot of coffee.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Wednesday, November 1, 2006 1:05 AM by ScottGu

Hi Caleb,

I try not to sleep -- it is very time inefficient. :-)

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Saturday, November 4, 2006 9:22 AM by Wayne Dehart
I too am experiencing the same symptoms with Beta 1. Firefox works well, but IE 6, sp1 gets 'sys' is undefined the first time the page is attempted to be loaded. Clicking 'refresh' in IE and upon page reload, the page loads fine. Any help is greatly appreciated.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Saturday, November 4, 2006 1:48 PM by ScottGu

Hi Wayne,

Can you send me email (scottgu@microsoft.com) with more details about this issue?

We've seen a few reports of this and are trying to track down exactly what is causing it (right now it look like a possible patch issue within IE).

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 9:01 AM by Jason
Having the same problem, tested on 4 computers, with IE6 (with all critical patches), IE7, and FireFox.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 10:35 AM by Arnout Symoens
Scott, I downloaded the Beta 2 Atlas Extensions, which work great. I download the Beta 2 Ajax Control Toolkit (nosource) package and installed it . When opening the sample website with Visual Studio 2005, it failed. The error was about assembly could not be loaded, etc. I removed the original AjaxControlkit.dll from the project, downloaded the Ajax Control kit full, copied the dll out of that one, and added it to my project. When I run it now, the sample website loads, but clicking any demo control fails with an error telling sys is undefined. Any solutions ? Greets Arnout Symoens

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 2:02 PM by Jason
I am also experiencing the IE6 'sys is undefined ' issue (no problem in Firefox). Google tells me that I am not alone. Do you have an update on the status of this problem?

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 2:52 PM by ScottGu

Hi Jason,

The Beta2 release requires a new entry in the web.config file, and this sample was built using Beta1.

My blog post here describes the entry to add: http://weblogs.asp.net/scottgu/archive/2006/11/08/ASP.NET-AJAX-1.0-Beta-2-Release.aspx

Once you do this the sample should work fine.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 2:53 PM by ScottGu

Hi Arnout,

Any chance you could post this question on the ASP.NET AJAX Control Toolkit forum on http://forums.asp.net

The team monitors this forum pretty closely and should be able to help.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 10, 2006 3:02 PM by Jason
Scott I assume that you are referring to the section indicating the need to add an entry for ScriptResource.axd in your 'ASP.NET AJAX 1.0 Beta 2 Release' posting. We did make this change during the upgrade to beta 2 but we still receive this error with IE 6 (but not with IE 7 or FF)

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Saturday, November 11, 2006 12:25 PM by ScottGu

Hi Jason,

Can you send me email with more details about this?  I'd like to them loop you in with a few folks to help investigate and figure out what is going wrong.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, November 14, 2006 11:35 AM by sam
I started getting the error when installed Beta 2. No problems in Beta 1. Interestingly, on my local machine its working fine. Then another developer ran into this problem on his machine, and now finally when i pushed everything to QA I am running into the error as well. 'Sys' is undefined..

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, November 14, 2006 1:39 PM by ScottGu

Hi Sam,

The issue you are running into is because the web.config file in the sample needs to be updated for Beta2.  This post talks about how to-do this (it is the last paragraph of the post): http://weblogs.asp.net/scottgu/archive/2006/11/08/ASP.NET-AJAX-1.0-Beta-2-Release.aspx

Hope this helps,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, November 14, 2006 2:50 PM by Sam

Hi Scott,

After downgrading to Beta 1, I was still getting same error in Test site. I added this bit and that seems to have solved, at least on Beta 1. I am not going to upgrade to Beta 2 yet to see if it solved that also.

<location path="ScriptResource.axd">

<system.web>

<authorization>

<allow users="*"/>

</authorization>

</system.web>

</location>

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, November 17, 2006 5:17 PM by Michael De Lorenzo

I'm running into the same issue with the 'Sys' is undefined error since upgrading to BETA 2.  My site worked great in BETA 1 - did I make a mistake in trying to upgrade?

It seemed related to the use of ComponentArt's Web.UI controls, but after upgrading it seemed to alleviate the problem.  But alas, they're back!

I've added the ScritResource.axd HttpHandler and I still get the issue, but not on every page.

Please help!

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Sunday, November 19, 2006 5:08 PM by ScottGu

Hi Michael,

Can you send me details about the issue you are running into and attach your web.config file in an email?  I'll then have someone on the team investigate and help.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Saturday, November 25, 2006 10:28 AM by Sean

I too am getting this same sys is undefined issue, I was curious to find out whether others who have recieved this problem were using forms authentication as it only seems to have shown up after I started to use forms authentication, it usually happens after some kind of async postback has happened.. btw I also corrected the web config when upgrading to beta 2 and was recieving no errors until i changed over to forms authentication

kind regards,

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Sunday, November 26, 2006 6:32 AM by Sean

Just to follow up, I tracked my error to be inside the global.asax inside Protected Sub Application_AcquireRequestState(ByVal sender As Object, ByVal e As EventArgs), why it was causing it to have that sys undefined error i don't know but fix the problem inside there seems to have rectified my problem, thanks anyway

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, November 28, 2006 4:07 AM by Yogesh

With forms authentication the <location> block mentioned by Sam needs to be added to web.config in addition to <httpHandler> to resolve the 'Sys' is undefined error in Beta 2.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Friday, December 1, 2006 2:05 PM by Volkan

Hi Scott,

I have Formview and UpdatePanel inmy aspx page and would like to take advantage of AJAX technology, but I get this error.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Type 'Microsoft.Web.UI.UpdatePanel' does not have a public property named 'FormView'.

Source Error:

Line 23:                            

Line 24: <Atlas:UpdatePanel ID="UpdatePanel1" runat="server">

Line 25:<asp:FormView ID="FormView1" runat="server" DataKeyNames="ContactID" DataSourceID="SqlDataSource5">

Line 26:                                

Line 27:<InsertItemTemplate>

Thank you.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Saturday, December 2, 2006 7:50 PM by ScottGu

Hi Volkan,

The problem you have above is that you aren't nesting the <asp:formView> control within a <ContentTemplate>.  You need to have this within updatepanel before you declare controls within it.

Hope this helps,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Wednesday, December 6, 2006 12:19 AM by ScottGu

Hi Sean,

Any chance you could send me an email describing this issue more (scottgu@microsoft.com)?

I'll then loop-in someone from my team who can help investigate and get back to you.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, December 11, 2006 6:38 AM by StefanO

I had the same sys undefined error in my test environment (development worked fine). I solved it by copying the Microsoft.Web.Preview.dll in to the bin-folder of my web. I think the handler for scriptResource.axd, is not able to extract the embedded resources out of Microsoft.Web.Preview.dll, if it resides in the GAC. Hope, that helps.

Stefan

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, December 11, 2006 10:21 AM by Sean

Hi Scott,

I emailed you in regards to my previous problem, trying to reproduce the problem in a test project is a work in progress as I said in the email, but I had an additional query, I wasn't sure whether to hassle you about it via email though, so I thought I'd ask here, I'm not sure whether it relates to the update panel, but I'm sure it relates to asp.net ajax, while making my test project I noticed the size of the page using asp.net ajax, I have this test project and it has a control with a panel, a textbox, a label and 2 linkbuttons in it, I have a master page with a link, and a default page with 2 panels and a link, the transferred page size is 408kb, does that sound right to you, as to me that size seems waaay to large for what it is.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, December 11, 2006 10:36 AM by ScottGu

Hi Sean,

That sounds pretty odd - you definitely shouldn't be seeing a download size that big.

Two questions:

1) Can you check your web.config file to make sure that you have debug="false" set?  It could be that we are outputting the debug JavaScript scripts which are big (since they include extra assert/validation logic).

2) If you still see this size feel free to send me a sample that repros it.

Thanks,

Scott

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, December 18, 2006 6:25 AM by Sean

Scott,

To follow up on my last problem, I have managed to work around the issue by referencing the scriptmanager and directly registering the lbUpload button as a postback control:

   Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

       'force the lbUpload button to cause a postback even though it is contained in an updatepanel..

       sm = CType(Parent.FindControl("MasterScriptManager"), ScriptManager)

       sm.RegisterPostBackControl(lbUpload)

   End Sub

Thanks :)

kind regards,

Sean.

# re: Tip/Trick: Unknow error it is display on popup window

Thursday, December 21, 2006 7:26 AM by Lalit mohan pradhan

Hi All,

I have used Atlas when i am click the button.

I have found error like "Unknow error"

Plz help me.

Lalit

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, December 26, 2006 5:30 AM by Amit Lohogaonkar

Hi,

We have aspx pages with ajax beta updatepanel and scriptmanager.

When session ends it shows message sys.webform.pagerequestparsererror excepition and do nothing after that.How to catch this exception and redirect page to login again.

We used  

protected void  scriptManager1_AsyncPostBackError but did not work.

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Monday, January 1, 2007 12:09 PM by Paul B

None of this stuff worked for me but the below did.. I know it's wrong, but I did it anyway,  accessing private properties. I hard coded this to prove the concept, you'll need to find the control for each one and get its clientid and uniqueid and add it to a string and spit out the below statement to make any control ont he page no matter how nested, master pages, etc. cause a postback. Sure woul dbe nice if there was a javascript function we could attach to a button and call Set_isPostback() or something.

       var prm = Sys.WebForms.PageRequestManager.getInstance();

       prm._postBackControlIDs = new Array("ctl00$AdminContent$GridView1$ctl06$AddButton");

       prm._postBackControlClientIDs = new Array("ctl00_AdminContent_GridView1_ctl06_AddButton");

# Any resolution for the 'Sys' is undefined error

Wednesday, January 10, 2007 5:18 PM by puneboy

I have AJAX ASP.NET RC1 installed and I am getting  the 'Sys' is undefined error. Surpriseingly AJAX controltoolkit samples work great but when I try to use UpdatePanel in my project and put datagrid in it, I am getting this error on clicking Edit or jut visitng this page.

Did you or your team found any resolution?

Thanks

# re: Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

Tuesday, January 16, 2007 1:40 AM by Søren Granfeldt

Just another hint; I had the following in my Global.asax:

Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)

       Dim P As Page = HttpContext.Current.Handler

End Sub

And that caused a 'Sys is undefined' to occur; commented out the 'Dim P As Page = HttpContext.Current.Handler' statement and the error went away (btw using RC1 AJAX)

Regards,

Soren, Denmark