Düzenle

Aracılığıyla paylaş


ClientScriptManager.IsOnSubmitStatementRegistered Method

Definition

Determines whether the OnSubmit statement is registered with the Page object.

Overloads

IsOnSubmitStatementRegistered(Type, String)

Determines whether the OnSubmit statement is registered with the Page object using the specified key and type.

IsOnSubmitStatementRegistered(String)

Determines whether the OnSubmit statement is registered with the Page object using the specified key.

IsOnSubmitStatementRegistered(Type, String)

Determines whether the OnSubmit statement is registered with the Page object using the specified key and type.

public:
 bool IsOnSubmitStatementRegistered(Type ^ type, System::String ^ key);
public bool IsOnSubmitStatementRegistered (Type type, string key);
member this.IsOnSubmitStatementRegistered : Type * string -> bool
Public Function IsOnSubmitStatementRegistered (type As Type, key As String) As Boolean

Parameters

type
Type

The type of the OnSubmit statement to search for.

key
String

The key of the OnSubmit statement to search for.

Returns

true if the OnSubmit statement is registered; otherwise, false.

Exceptions

The OnSubmit statement type is null.

Examples

The following code example demonstrates the use of the IsOnSubmitStatementRegistered method. A script named OnSubmitScript is registered with the Page so that when the page's form is submitted the script is invoked.

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  public void Page_Load(Object sender, EventArgs e)
  {
    // Define the name and type of the client script on the page.
    String csname = "OnSubmitScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the OnSubmit statement is already registered.
    if (!cs.IsOnSubmitStatementRegistered(cstype, csname))
    {
      String cstext = "document.write('Text from OnSubmit statement');";
      cs.RegisterOnSubmitStatement(cstype, csname, cstext);
    }

  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     <input type="submit"
            value="Submit" />
     </form>
  </body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Define the name and type of the client script on the page.
    Dim csname As String = "OnSubmitScript"
    Dim cstype As Type = Me.GetType()
    
    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript
    
    ' Check to see if the OnSubmit statement is already registered.
    If (Not cs.IsOnSubmitStatementRegistered(cstype, csname)) Then
      
      Dim cstext As String = "document.write('Text from OnSubmit statement.');"
      cs.RegisterOnSubmitStatement(cstype, csname, cstext)
      
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     <input type="submit"
            value="Submit" />
     </form>
  </body>
</html>

Remarks

Call this method before calling the RegisterOnSubmitStatement method to avoid registering duplicate statements. This is particularly important if the statement requires a large amount of server resources to create.

A statement is uniquely identified by its key and its type. Statements with the same key and type are considered duplicates. You specify the type based on the object that will be accessing the resource. For instance, when using a Page instance to access the resource, you specify the Page type.

See also

Applies to

IsOnSubmitStatementRegistered(String)

Determines whether the OnSubmit statement is registered with the Page object using the specified key.

public:
 bool IsOnSubmitStatementRegistered(System::String ^ key);
public bool IsOnSubmitStatementRegistered (string key);
member this.IsOnSubmitStatementRegistered : string -> bool
Public Function IsOnSubmitStatementRegistered (key As String) As Boolean

Parameters

key
String

The key of the OnSubmit statement to search for.

Returns

true if the OnSubmit statement is registered; otherwise, false.

Remarks

Call this method before calling the RegisterOnSubmitStatement method to avoid registering duplicate OnSubmit statements. This is particularly important if the statement requires a large amount of server resources to create.

A statement is uniquely identified by its key and its type. Statements with the same key and type are considered duplicates.

This overload of the IsOnSubmitStatementRegistered method calls the overload that takes both a key and a type parameter with the type set as a Page object

See also

Applies to