js ajax 出错打印出整个页面,Ajax中Response.Write输出js脚本出错的解决方案

Ajax中Response.Write输出js脚本出错的解决方案

Ajax 3.5是不是有改动.后来经过尝试将ScriptManager.RegisterStartupScript(updatePanel1, typeof(UpdatePanel), "aaa", "alert('数据添加成功!')",true);中最后的true变为ScriptManager.RegisterStartupScript(updatePanel1, typeof(UpdatePanel), "aaa", "alert('数据添加成功!')",false);就可以了.下面写一个通用的消息提示类.

public class MessageBox

{

private HttpContext myContext = null;

public MessageBox(HttpContext CurrentContext)

{

myContext = CurrentContext;

}

/// /// 自定义弹出窗口内容

///

///

public void Show(string msg)

{

//myContext.Response.Write("alert('" + msg + "');");

ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "alert('" + msg + "');", false);

}

/// /// 自定义弹出窗口内容并转向一个新的页面

///

/// 自定义消息

/// 需要转到的新页面

public void Show(string msg,string Url)

{

//myContext.Response.Write("alert('" + msg + "');网页特效:location='"+Url+"';");

ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "alert('" + msg + "');javascript:location='" + Url + "';", false);

}

/// /// 自定义弹出窗口内容,自定义是否关闭当前页面

///

///

///

public void Show(string msg, bool close)

{

if (close)

{

// myContext.Response.Write("alert('" + msg + "');javascript:window.close();");

ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "alert('" + msg + "');javascript:window.close();", false);

}

else

{

//myContext.Response.Write("alert('" + msg + "');");

ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "alert('" + msg + "');javascript:window.close();", false);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值