ClientScriptManager.IsOnSubmitStatementRegistered Method (Type, String)

 

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

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

public bool IsOnSubmitStatementRegistered(
	Type type,
	string key
)

Parameters

type
Type: System.Type

The type of the OnSubmit statement to search for.

key
Type: System.String

The key of the OnSubmit statement to search for.

Return Value

Type: System.Boolean

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

Exception Condition
ArgumentNullException

The OnSubmit statement type is null.

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.

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>

.NET Framework
Available since 2.0
Return to top
Show: