Hi
I have an UpdatePanel using a trigger from the click event on a button. Everything seems to works ok, the click event hits the code-behind. My question is, how do you tell the page that an exception occured in the code-behind?
Many thanks
Craig
Hi,you can use the ErrorTemplate provided by the ScriptManager control:
<ErrorTemplate>
<div>
There was an error processing your action. <br />
<span id="errorMessageLabel"></span>
<hr />
<button type="button" id="okButton">OK</button>
</div>
</ErrorTemplate>
This way, all the controls on the page will be disabled and the Exception message will be displayed in a nice overlay. You can customize the appearance of the ErrorTemplate but notice that the ids in red are "hard-coded-ids". The first is a label that displays the error message, the second is a button that re-enables the page.
Moreover, you can catch the PageError event of the ScriptManager control:
<atlas:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true"
OnPageError="ScriptManager1_PageError">
and, in codebehind, declare an event handler in which you can do custom processing of the error message:
protected void ScriptManager1_PageError(object sender, PageErrorEventArgs e)
{
e.ErrorMessage = "Unable to complete the request because: "
+ "<strong>"
+ e.Error.Message
+ "</strong>";
}
The PageErrorEventArgs instance exposes two properties:ErrorMessage
that can be set to the error message that the client will receive;Error
that returns a reference to the Exception instance.
Hi Garbin
My script manager is in a MasterPage:
<atlas:ScriptManagerID="scriptmanager"runat="Server"EnablePartialRendering="true"/>
How can I access the<ErrorTemplate> or the PageError event from the MasterPage in my aspx page which uses:
<atlas:ScriptManagerProxyID="scriptManager"runat="server"EnableScriptComponents="false">
I have a user control which renders a nice messagebox, so to be consistant I'd want to use that.
Thanks for your help.
Craig
Hi,
you cannot add an ErrorTemplate to the ScriptManagerProxy, but only to the ScriptManager control. But to preserve consistency it seems to me a good idea to have an ErrorTemplate in a MasterPage.
You can also drop in the ErrorTemplate a UserControl, just ensure that the ScriptManager is located inside the <form />. One problem however is that, as you know, the UserControl modifies the ClientID of its child controls and the ScriptManager relies on two hard-coded ids ("errorMessageLabel" and "okButton") to work as expected. One solution would be to assign these ids to non-server controls.
No comments:
Post a Comment