在项目中写一个 JavaScript 弹出窗口 通用类

来源:互联网 发布:手机淘宝账号怎么注册 编辑:程序博客网 时间:2024/05/26 20:23

public class MessageBox
 {

  private static string ScriptBegin = "<script language=/"JavaScript/">";
  private static string ScriptEnd = "</script>";
  public MessageBox()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  //将javascript写到页面
  public static void PushToIE(string memuList)
  {
   string ConfirmContent=memuList;

   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
   
   System.Web.UI.Page ParameterPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.RegisterStartupScript("confirm",ConfirmContent);
  }

//反回javascript

  public static string ReturnStr(string str)
  {
   StringBuilder Msg=new StringBuilder();;
   Msg.Append("<script language=javascript >");
   Msg.Append(str);
   Msg.Append("</script>");
   return Msg.ToString();
  }
  /// <summary>
  /// 弹出提示
  /// </summary>
  /// <param name="message">提示内容</param></param></param>
   public static void MsgBox(string message)
  {

   string ConfirmContent="alert(/"" +message+ "/");";

   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
   
   System.Web.UI.Page ParameterPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.RegisterStartupScript("confirm",ConfirmContent);

  }

//打开一个新窗口

  public static void OpenNewWin(string Url)
  {
   string ConfirmContent="window.open(/"" +Url+ "/");";

   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
   
   System.Web.UI.Page ParameterPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.RegisterStartupScript("confirm",ConfirmContent);
  }

//打开一个对话框 showModalDialog

public static void OpenshowModalDialog(string Url)

{

   string ConfirmContent="showModalDialog(/"" +Url+ "/");";

   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
   
   System.Web.UI.Page ParameterPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.RegisterStartupScript("confirm",ConfirmContent);

}
 } 

原创粉丝点击