System.Web.UI.Page.RegisterStartupScript(string, string)”已过时的解决办法

警告 1“System.Web.UI.Page.RegisterStartupScript(string, string)”已过时:“The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202”C:\Inetpub\wwwroot\BeylandSoft05\BeylandSoft05\BeylandSoft05\BeylandSoft.cs1245 6 BeylandSoft05

_page.RegisterStartupScript("","<script language='javascript'>alert('文件不存在!');</script>"); 



 过时的语句:Page.RegisterStartupScript("calis", "<script>showPopWin('" + Caption + "', null,'" + this.ID + "');</script>");


使用新的语句:ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(), "Startup", "<script>showPopWin('" + Caption + "', null,'" + this.ID + "');</script>",true);




ClientScriptManager.RegisterStartupScript 方法 (Type, String, String, Boolean)


命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)


public void RegisterStartupScript (
	Type type,
	string key,
	string script,
	bool addScriptTags
)
参数
type

要注册的启动脚本的类型。

key

要注册的启动脚本的键。

script

要注册的启动脚本文本。

addScriptTags

指示是否添加脚本标记的布尔值。

下面是MSDN给出的实例!
<%@ Page Language="C#"%>
<script runat="server">
  public void Page_Load(Object sender, EventArgs e)
  {
    // Define the name and type of the client scripts on the page.
    String csname1 = "PopupScript";
    String csname2 = "ButtonClickScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname1))
    {
      String cstext1 = "alert('Hello World');";
      cs.RegisterStartupScript(cstype, csname1, cstext1, true);
    }

    // Check to see if the client script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
    {
      StringBuilder cstext2 = new StringBuilder();
      cstext2.Append("<script type=text/javascript> function DoClick() {");
      cstext2.Append("Form1.Message.value='Text from client script.'} </");
      cstext2.Append("script>");
      cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
    }
  }
</script>
<html>
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
	 <form id="Form1"
         runat="server">
		<input type="text" id="Message"> <input type="button" value="ClickMe" οnclick="DoClick()">
	 </form>
  </body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值