void Application_Error(object sender, EventArgs e)
{
if (Session["id"] == null)
{
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');location.href=\'Default.aspx\';</Script>");
}
总是提示常量中有换行符
用过这几种方法倒是不提示了
第一种 StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"text/javascript\"> \n");
string str = "lianjiechaoshi ~~~~";
sb.Append("alert(\"" + str.Trim() + "\"); \n");
string url = "Default.aspx";
sb.Append("window.location.href=\"" + url.Trim() + "\";\n");
sb.Append("</ script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
第二种 HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');location.href=\'Default.aspx\';</Scr"+"ipt>"); 但是代码就不起作用了啊!!!!!!
报错的信息是未将对象引用到实例?很奇怪在线等~~~~各位高手帮帮忙啊!
解决方案 »
- 权限显示
- 高分求ASP.NET to oracle数据溢出错误
- 一个查询的小问题,请大师给指点下吧!!
- 关于在TABLECELL中引用样式不起效的问题
- 晕!新来个同事告诉我说Session不是全局变量...我不知道是不是我理解错了!
- 关于.net中Jmail发送邮件的问题~!!!
- The compiler of ASP.NET?
- 怎样判断 页面里是否存在 某 服务器控件(如:id = TABLE1) ,并将其不可视 visible = false;
- 很着急的作业问题
- 改变图片大小并保存
- js如何传递参数
- select * from table where id=3 和select @num=count(*) from table如何在同一个存储过程中使用
{
if (Session["id"] == null)
{
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');location.href=\'Default.aspx\';</Script>");
}---------------------
不用\',直接用单引号,如下:
void Application_Error(object sender, EventArgs e)
{
if (Session["id"] == null)
{
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');location.href='Default.aspx';</Script>");
}
=\'Default.aspx\' -> ='Default.aspx'
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');window.location='Default.aspx';</Script>");
前面的script是小写,后面的是大写
一个大写,一个小写,不一致呀
应该是转义符的问题,但是我不知道怎么解决!!
直接用HttpContext.Current.Response.Redirect("Default.aspx")都可以实现,
就是想在重定向的时候加个弹出对话框就卡在那了 , 郁闷了好久啊~~~
各位高手帮帮忙啊~~~~~~怎么在Global.asax文件里正确实现 提示对话框,然后跳转嘛~~~~~急啊!!!!
错误是该应用程序中的文件无效
在Global.asax的session_start或Application_Error中跳转可以实现
if (Session["id"] == null)
{
HttpContext.Current.Response.Redirect("Default.aspx");
}但是想要弹出对话框的这段代码倒是没有报错了
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('连接超时');window.location='Default.aspx';<///script>");
就是对话框始终没有出来。
放弃了,我还是在page_load里写吧。
自己总结一下,结贴了。
谢谢各位的热心帮助,非常感谢!