1. IsStartupScriptRegistered: indicates whether the script is enabled for the object.
2. IsClientScriptBlockRegistered: indicates whether the client script block is registered.
3. IsClientScriptIncludeRegistered: indicates whether the object is registered with a client script.
Example 1:
String info = "<script> alert ('Are you good? '); </Script> ";
// Determine whether the event is registered. Write to the region: <body >---- <script> </body>
If (! Page. ClientScript. IsStartupScriptRegistered ("test "))
{
// Dynamically register and execute Javascript
Page. ClientScript. RegisterStartupScript (this. GetType (), "test", info );
}
Example 2:
Aspx file:
Name: <input id = "txtUserName" type = "text"/>
<Input id = "btnSubmit" type = "button" value = "OK" onclick = "salert (txtUserName. value)"/>
Cs file:
String info = "function salert (userName) {alert ('your name: '+ userName )}";
// Determine whether test has been registered
If (! Page. ClientScript. IsClientScriptBlockRegistered (this. GetType (), "test "))
{
// Dynamically register Javascript
Page. ClientScript. RegisterClientScriptBlock (this. GetType (), "test", info, true );
}
Example 3:
Aspx file:
Name: <input id = "txtUserName" type = "text"/>
<Input id = "btnSubmit" type = "button" value = "OK" onclick = "salert (txtUserName. value)"/>
Jscript. js
Function salert (userName)
{
Alert ("Your name" + userName );
}
Cs file:
// Determine whether test has been registered
If (! Page. ClientScript. IsClientScriptIncludeRegistered (this. GetType (), "test "))
{
// Dynamically register Javascript
Page. ClientScript. RegisterClientScriptInclude ("test", "Jscript. js ");
}