后台弹出消息框的集中方式:
1 Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>alert('错误: \n 错误信息');location.href='user.aspx';</script>"); 2 Response.Write("<script>alert('错误: \n"错误信息’);
如果在try-catch 中 需要显示错误的信息
需要将"'" ," "替换,否则无法 alert无法弹出,
1 try 2 { 3 //...... 4 } 5 catch (Exception ee) 6 { 7 Response.Write("<script>alert('错误: \n" + ee.Message.Replace("'", "\'").Replace(" ", "\r\n") + ee.StackTrace.Replace("'", "\'").Replace(" ", "\r\n") + "');location.href='user.aspx';</script>"); 8 9 }
利用JavaScript alert() 弹出错误信息,但是错误信息中 ee.Message 中的 "'" ," " , alert无法弹出,需要替换。
location.href='user.aspx' 弹出窗口点击后 跳转页面