<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" AllowCustomErrorsRedirect="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
In web.config,
<customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>
The error will be redirected to the custom error page.