1. 程式人生 > >asp.net 後臺利用alert彈出錯誤信息消息框

asp.net 後臺利用alert彈出錯誤信息消息框

tac pla rac java use art exceptio ati 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‘ 彈出窗口點擊後 跳轉頁面

asp.net 後臺利用alert彈出錯誤信息消息框