App_Code下的类中运用ClientScriptManager弹出窗口
public class Class1 : System.Web.UI.Page{ public Class1() { } public void aa(string strMessage) { ClientScriptManager cs = Page.ClientScript; Type cstype = this.GetType(); string csstring = "PopupScript"; string cstext = "alert('" + strMessage + "');"; cs.RegisterStartupScript(cstype, csstring, cstext, true); }}public class Class1{ public Class1() { } public void aa(string strMessage) { Page page = (Page)System.Web.HttpContext.Current.Handler; ClientScriptManager cs = page.ClientScript; Type cstype = this.GetType(); string csstring = "PopupScript"; string cstext = "alert('" + strMessage + "');"; cs.RegisterStartupScript(cstype, csstring, cstext, true); }}
[解决办法]
/// <summary> /// 警告框 /// </summary> /// <param name="_Msg">警告字串</param> /// <param name="_Page">this</param> /// <returns>警告框JS</returns> public static object Alert(string _Msg, Page _Page) { string StrScript; StrScript = ("<script language=javascript>"); StrScript += ("alert('" + _Msg + "');"); StrScript += ("</script>"); _Page.ClientScript.RegisterStartupScript(_Page.GetType(), "MsgBox", StrScript.ToString()); return StrScript; }
[解决办法]
public void aa(string strMessage) { string cstext = "alert('" + strMessage + "');"; ((Page)HttpContext.Current.Handler).ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), cstext, true); }