日期:2014-05-17 浏览次数:20503 次
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); }