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);
}
}
}