XP 32bit
Visual Studio 2008
.NET 3.5 SP1
IE 7.0
I have not installed the AJAX toolkit from this site - I am using what came 'out of the box' with Visual Studio 2008.
I am attempting a simple test with the UpdatePanel. I have set up the example outlined here:
http://msdn.microsoft.com/en-us/library/bb398934.aspx
However, when I cause an exception to be thrown on the server (by performing a calculation like 12/0), the alert box is not shown. Instead the text 'Error on page.' is shown on the status bar in IE on the left and clicking this gives the details of the error as:
Line: 4724
Char: 21
Error: Sys.WebForms.PageRequestManagerServerErrorException: Attempted to divide by zero. You can't divide 12 by 0.
Code: 0
Url: http://localhost/test/Default.aspx
I've published the site to IIS and tried and this makes no difference.
I am expecting an alert box to be shown by the client browser when the exception is detected by the AJAX code on the client side.
Any help would be much appreciated. Have reproduced the code I am running below (from the link above):
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
try
{
int a = Int32.Parse(TextBox1.Text);
int b = Int32.Parse(TextBox2.Text);
int res = a / b;
Label1.Text = res.ToString();
}
catch (Exception ex)
{
if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
{
ex.Data["ExtraInfo"] = " You can't divide " +
TextBox1.Text + " by " + TextBox2.Text + ".";
}
throw ex;
}
}
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
if (e.Exception.Data["ExtraInfo"] != null)
{
ScriptManager1.AsyncPostBackErrorMessage =
e.Exception.Message +
e.Exception.Data["ExtraInfo"].ToString();
}
else
{
ScriptManager1.AsyncPostBackErrorMessage =
"An unspecified error occurred.";
}
}
</script>
<html >
<head id="Head1" runat="server">
<title>Partial-Page Update Error Handling Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox>
/
<asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox>
=
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>