Salut,
J'aurais besoin d'aide sur la gestion d'exceptions en ASP.Net.
Dans une application ASP.Net, lorsqu'une exception C# est lancée, la méthode C# OnError est appelée. Dans cette méthode, j'aimerais insérer du code Javascript dans la page afin d'afficher pour l'instant une alertbox Javascript.
Comment réaliser cela ?
Pour l'instant, j'ai testé le code suivant, qui ne réussit pas à afficher l'alertbox.
1) Page Default.aspx :
Code :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SandBoxWeb._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="scriptManager1" /> <div> <asp:Button runat="server" ID="button1" Text="Cliquez-moi !" OnClick="button1_OnClick" /> <p /> </div> </form> </body> </html>
|
2) Code-behind Default.aspx.cs :
Code :
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void button1_OnClick(object sender, EventArgs e) { throw new Exception ("test" ); } protected override void OnError(EventArgs e) { var js_code = "alert('test');"; ScriptManager. RegisterClientScriptBlock(this, typeof(Page ), "Test", js_code, true); } }
|