警告 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>