在使用了Ajax.net的页面里不能使用Response.Write,要用ScriptManager.Register......,我想把下面的代码写成一个通用类来调用,但是提示错误: “XXXX”并不包含“Page”的定义。应该怎么改呢?出错的代码:
public void sendAjaxAlert(string msg)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "msg", "alert('" + msg + "');", true);
}说明:放在在Aspx页面的后台代码中没问题,单独写在一个*.CS文件中就出错。
public void sendAjaxAlert(string msg)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "msg", "alert('" + msg + "');", true);
}说明:放在在Aspx页面的后台代码中没问题,单独写在一个*.CS文件中就出错。
public void sendAjaxAlert(string msg,System.Web.UI.Page page)
{
ScriptManager.RegisterClientScriptBlock(page, this.GetType(), "msg", "alert('" + msg + "');", true);
} 一般用
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdatePanel1", "alert(1)", true);
ScriptManager.RegisterStartupScript(this.UpdatePanel2, this.GetType(), "UpdatePanel2", "alert(2)", true);
public void sendAjaxAlert(System.Web.UI.Page page, string msg)
{
ScriptManager.RegisterClientScriptBlock(page, this.GetType(), "msg", "alert('" + msg + "');", true);
}
这样不知道行不行
{
public static void SendAlert(string msg, System.Web.UI.Page page)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('" + msg + "');", true);
}
}
{
public static void SendAlert(string msg, System.Web.UI.Page page)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('" + msg + "');", true);
}
}在1楼、2楼的基础上修改了一下(红色部分)。 用ScriptManager.RegisterStartupScript或ScriptManager.RegisterClientScriptBlock都可以。 感谢各位!