ScriptManager.RegisterStartupScript 方法

定义

ScriptManager 控件注册一个启动脚本块并将此脚本块添加到页面中。Registers a startup script block with the ScriptManager control and adds the script block to the page.

重载

RegisterStartupScript(Control, Type, String, String, Boolean)

使用 ScriptManager 控件为 UpdatePanel 中的某个控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.

RegisterStartupScript(Page, Type, String, String, Boolean)

为每个异步回发向 ScriptManager 控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for every asynchronous postback with the ScriptManager control and adds the script block to the page.

RegisterStartupScript(Control, Type, String, String, Boolean)

使用 ScriptManager 控件为 UpdatePanel 中的某个控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.

public:
 static void RegisterStartupScript(System::Web::UI::Control ^ control, Type ^ type, System::String ^ key, System::String ^ script, bool addScriptTags);
public static void RegisterStartupScript (System.Web.UI.Control control, Type type, string key, string script, bool addScriptTags);
static member RegisterStartupScript : System.Web.UI.Control * Type * string * string * bool -> unit
Public Shared Sub RegisterStartupScript (control As Control, type As Type, key As String, script As String, addScriptTags As Boolean)

参数

control
Control

正在注册客户端脚本块的控件。The control that is registering the client script block.

type
Type

客户端脚本块的类型。The type of the client script block. 通常使用 typeof 运算符 (C#) 或 GetType 运算符 (Visual Basic) 来指定此参数,以检索正在注册脚本的控件的类型。This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.

key
String

脚本块的唯一标识符。A unique identifier for the script block.

script
String

要注册的脚本。The script to register.

addScriptTags
Boolean

如果用 <script></script> 标记括起此脚本块,则为 true;否则为 falsetrue to enclose the script block with <script> and </script> tags; otherwise, false.

例外

controlnullcontrol is null.

-or- typenulltype is null.

control 不在该页面的控件树中。control is not in the page's control tree.

注解

使用 RegisterStartupScript 方法来注册与部分页面呈现兼容且没有 Microsoft Ajax 库依赖项的页的启动脚本块。You use the RegisterStartupScript method to register a startup script block for a page that is compatible with partial-page rendering and that has no Microsoft Ajax Library dependencies. 仅当正在更新的控件在正在更新的控件中时,才会将使用此方法注册的启动脚本块发送到页面 UpdatePanelStartup script blocks that are registered by using this method are sent to the page only when the control that is registering the block is inside an UpdatePanel control that is being updated. 若要在每次发生异步回发时注册一个启动脚本块,请使用 RegisterStartupScript(Page, Type, String, String, Boolean) 此方法的重载。To register a startup script block every time that an asynchronous postback occurs, use the RegisterStartupScript(Page, Type, String, String, Boolean) overload of this method.

如果要注册的启动脚本与部分页面更新不相关,并且要在初始页面呈现期间只注册一次脚本,请使用 RegisterStartupScript 类的方法 ClientScriptManagerIf you want to register a startup script that does not pertain to partial-page updates, and if you want to register the script only one time during initial page rendering, use the RegisterStartupScript method of the ClientScriptManager class. 可以 ClientScriptManager 从页的属性中获取对该对象的引用 ClientScriptYou can get a reference to the ClientScriptManager object from the ClientScript property of the page.

RegisterStartupScript当页面完成加载但在引发页面的客户端事件之前,将执行由方法呈现的脚本块 onloadThe script block that is rendered by the RegisterStartupScript method executes when the page finishes loading but before the page's client onload event is raised. 启动脚本块位于标记之前呈现的 ASP.NET 页面的底部 </form>Startup script blocks are located at the bottom of the rendered ASP.NET page just before the </form> tag.

不保证使用注册的启动脚本块 RegisterStartupScript 的输出顺序与它们的注册顺序相同。Startup script blocks that are registered by using RegisterStartupScript are not guaranteed to be output in the same order in which they are registered. 如果启动脚本块的顺序很重要,则使用 StringBuilder 对象以单个字符串的形式收集脚本块,然后将它们全部注册为一个启动脚本。If the order of the startup script blocks is important, use a StringBuilder object to gather the script blocks in a single string, and then register them all as a single startup script.

另请参阅

适用于

RegisterStartupScript(Page, Type, String, String, Boolean)

为每个异步回发向 ScriptManager 控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for every asynchronous postback with the ScriptManager control and adds the script block to the page.

public:
 static void RegisterStartupScript(System::Web::UI::Page ^ page, Type ^ type, System::String ^ key, System::String ^ script, bool addScriptTags);
public static void RegisterStartupScript (System.Web.UI.Page page, Type type, string key, string script, bool addScriptTags);
static member RegisterStartupScript : System.Web.UI.Page * Type * string * string * bool -> unit
Public Shared Sub RegisterStartupScript (page As Page, type As Type, key As String, script As String, addScriptTags As Boolean)

参数

page
Page

正在注册客户端脚本块的页对象。The page object that is registering the client script block.

type
Type

客户端脚本块的类型。The type of the client script block. 通常使用 typeof 运算符 (C#) 或 GetType 运算符 (Visual Basic) 来指定此参数,以检索正在注册脚本的控件的类型。This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.

key
String

脚本块的唯一标识符。A unique identifier for the script block.

script
String

要注册的脚本。The script to register.

addScriptTags
Boolean

如果用 <script></script> 标记括起此脚本块,则为 true;否则为 falsetrue to enclose the script block with <script> and </script> tags; otherwise, false.

注解

使用此方法来注册每次发生异步回发时都包含的启动脚本块。You use this method to register a startup script block that is included every time that an asynchronous postback occurs. 若要为控件内的控件注册脚本块 UpdatePanel ,以便仅在更新控件时注册脚本块 UpdatePanel ,请使用 RegisterStartupScript(Control, Type, String, String, Boolean) 此方法的重载。To register a script block for a control that is inside an UpdatePanel control so that the script block is registered only when the UpdatePanel control is updated, use the RegisterStartupScript(Control, Type, String, String, Boolean) overload of this method.

如果要注册的启动脚本与部分页面更新不相关,并且要在初始页面呈现期间只注册一次脚本,请使用 RegisterStartupScript 类的方法 ClientScriptManagerIf you want to register a startup script that does not pertain to partial-page updates, and if you want to register the script only one time during initial page rendering, use the RegisterStartupScript method of the ClientScriptManager class. 可以 ClientScriptManager 从页的属性中获取对该对象的引用 ClientScriptYou can get a reference to the ClientScriptManager object from the ClientScript property of the page.

另请参阅

适用于