C#后台调用前台页面js方法



方法1.
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "SetRadioName()", true);
方法2.
ClientScriptManager cs = Page.ClientScript;
  cs.RegisterStartupScript(this.GetType(), "", "<script type=\"text/javascript\">SubjectListener();</script>");

方法3.

 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tishi", "alert('你所查询的数据不存在!');", true);

方法4.
ClientScript.RegisterClientScriptBlock(this.GetType(), "tishi", "<script type=\"text/javascript\">alert('你所查询的数据不存在!');</script>");

 

5.公共方法:

/// <summary>
/// 显示提示消息对话框(alert)
/// </summary>
/// <param name="msg">消息内容</param>
 public static void ShowMessage(string msg)
  {
          Page page = HttpContext.Current.Handler as Page;
          if (page != null)
             page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "alert('" + msg.Replace("'","") + "');", true);
  }


你可能感兴趣的:(C#后台调用前台页面js方法)