zoh*_*air 4 c# asp.net custom-errors
我有一个ASP.NET Web应用程序,我想知道如何在抛出异常时显示错误消息框.
例如,
try
{
do something
}
catch
{
messagebox.write("error");
//[This isn't the correct syntax, just what I want to achieve]
}
Run Code Online (Sandbox Code Playgroud)
[消息框显示错误]
谢谢
大概你可以这样做:
try
{
//do something
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
if (!Page.IsStartupScriptRegistered("myErrorScript"))
{
Page.ClientScript.RegisterStartupScript("myErrorScript", script);
}
}
Run Code Online (Sandbox Code Playgroud)
但我建议您定义自定义Exception并将其丢弃到您需要的任何位置.在您的页面上捕获此自定义异常并注册您的消息框脚本.
| 归档时间: |
|
| 查看次数: |
95622 次 |
| 最近记录: |