asp.net 后台利用alert弹出错误信息消息框

后台弹出消息框的集中方式:

1 Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>alert('错误: \\n 错误信息');location.href='user.aspx';</script>");
2 Response.Write("<script>alert('错误: \\n"错误信息’);

如果在try-catch 中 需要显示错误的信息

需要将"'" ,"\r\n"替换,否则无法  alert无法弹出,

1 try
2 {
3 //......
4 }
5 catch (Exception ee)
6 {
7  Response.Write("<script>alert('错误: \\n" + ee.Message.Replace("'", "\\'").Replace("\r\n", "\\r\\n") + ee.StackTrace.Replace("'", "\\'").Replace("\r\n", "\\r\\n") + "');location.href='user.aspx';</script>");
8 
9 }

 

利用JavaScript alert() 弹出错误信息,但是错误信息中  ee.Message 中的 "'" ,"\r\n"  , alert无法弹出,需要替换。

location.href='user.aspx'  弹出窗口点击后 跳转页面

 

posted @ 2019-05-16 15:17  我去其他hi  阅读(1117)  评论(0编辑  收藏  举报