.NET Framework Class Library
ClientScriptManager..::.RegisterStartupScript Method (Type, String, String)

Registers the startup script with the Page object using a type, a key, and a script literal.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic (Declaration)
Public Sub RegisterStartupScript ( _
    type As Type, _
    key As String, _
    script As String _
)
Visual Basic (Usage)
Dim instance As ClientScriptManager
Dim type As Type
Dim key As String
Dim script As String

instance.RegisterStartupScript(type, _
    key, script)
C#
public void RegisterStartupScript(
    Type type,
    string key,
    string script
)
Visual C++
public:
void RegisterStartupScript(
    Type^ type, 
    String^ key, 
    String^ script
)
JScript
public function RegisterStartupScript(
    type : Type, 
    key : String, 
    script : String
)

Parameters

type
Type: System..::.Type
The type of the startup script to register.
key
Type: System..::.String
The key of the startup script to register.
script
Type: System..::.String
The startup script literal to register.
Remarks

A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Call the IsStartupScriptRegistered method to determine whether a startup script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script.

In this overload of the RegisterStartupScript method, you must make sure that the script provided in the script parameter is wrapped with a <script> element block.

The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised. The script blocks are not guaranteed to be output in the order they are registered. If the order of the script blocks is important, use a StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Community Content

EdSF
Bug/error using this overload
Unsure what this overload is for. The instructions explicitly state that you have to make sure your script text is enclosed in <script> tags. However, if you did, particularly in inline code (unsure if using master pages is a really contributing factor), you will get this error:

"Only content controls are allowed directly on a content page...."

Mentioned uncertainty of master pages being a contributing factor because although the error does seem to point to it (content page), and yes, I had this issue on a content page, using the this method's overload containing the Boolean addscripttags value works - re: it will add open/close script tags automatically.



Page view tracker