Ajax中Response.Write输出js脚本出错的解决方案
Ajax 3.5是不是有改动.后来经过尝试将ScriptManager.RegisterStartupScript(updatePanel1, typeof(UpdatePanel), "aaa", "",true);中最后的true变为ScriptManager.RegisterStartupScript(updatePanel1, typeof(UpdatePanel), "aaa", "",false);就可以了.下面写一个通用的消息提示类.
public class MessageBox
{
private HttpContext myContext = null;
public MessageBox(HttpContext CurrentContext)
{
myContext = CurrentContext;
}
///
/// 自定义弹出窗口内容
///
///
public void Show(string msg)
{
//myContext.Response.Write("");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "", false);
}
///
/// 自定义弹出窗口内容并转向一个新的页面
///
/// 自定义消息
/// 需要转到的新页面
public void Show(string msg,string Url)
{
//myContext.Response.Write("");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "", false);}
///
/// 自定义弹出窗口内容,自定义是否关闭当前页面
///
///
///
public void Show(string msg, bool close)
{
if (close)
{
// myContext.Response.Write("");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "", false);
}
else
{
//myContext.Response.Write("");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "", false);
}
}
}