Error handling behavior with and without UpdatePanel

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




UpdatePanel is my personal favorite in the whole AJAX framework, because it enables easy implementation more responsive web application. Years ago, on the beginning of ASP.NET I was asking myself, why ASP.NET has been by default designed to be irresponsive. Now it is a time to migrate all those controls in the world of AJAX. Exactly in this scenario UpdatePanel plays very important role. I would like to show in this post, that there is different error handling approach by using of one control with UpdatePanel and without it. That means that your existing controls may not handle errors as expected. Note that this behavior is not a bug. It is just a new design feature, which is not bad if you are aware of it.

To make it clear, let's take a look on the following example:

<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" CodeFile="Dummy.aspx.cs" Inherits="Dummy" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button 1" /></div>
            <atlas:ScriptManager id="ScriptManager"  EnablePartialRendering="true" runat="Server"></atlas:ScriptManager>
       <atlas:UpdatePanel ID="update" runat="server" Mode="Always">
               <asp:Button ID="Button2" runat="server" OnClick="Button_Click2" Text="Button 2" /></div>

This very simple example provides two buttons with postbacks. First button is just usual ASP.NET control, and the second one is placed into the UpdatePanel. Assume now, one error occurs, when any of buttons is pressed. That means, user press the button, and the page is invoked as a postback. This is exactly what happen by pressing of any of this two buttons. The question is: "What is expecting behavior, when the user presses the first and second button"? (No meter what sequence)

To demonstrate this implement the code behind file as shown in the next example:

public partial class Dummy : System.Web.UI.Page

    protected void Page_Load(object sender, EventArgs e)
            throw new Exception("damir error");

When the button is pressed, which is not in the UpdatePanel the page is not rendered at all. This is actually expected usual ASP.NET behavior.

Line 25:

Line 26: throw new Exception("damir error");

Line 27:

Line 28:

However, when the second button (inside of UpdatePanel) is pressed, the popup window with error messages is opened as shown on the image below. Just, be aware of these two patterns, by designing your controls for UpdatePanel.


Posted Jan 09 2007, 12:59 AM by Damir Dobric
Filed under:


Damir Dobric Posts wrote UpdatePanel behavior: Conditional or Always?
on 02-02-2007 1:04

ASP.NET AJAX framework (ATLAS) is shipped with a powerful control UdatePanel. The control offers very is a .Net Community Blog powered by daenet GmbH.