ClientScriptManager.IsOnSubmitStatementRegistered 方法

定义

确定 Page 对象是否注册了 OnSubmit 语句。Determines whether the OnSubmit statement is registered with the Page object.

重载

IsOnSubmitStatementRegistered(Type, String)

确定 Page 对象是否使用指定的键和类型注册了 OnSubmit 语句。Determines whether the OnSubmit statement is registered with the Page object using the specified key and type.

IsOnSubmitStatementRegistered(String)

确定 Page 对象是否使用指定键注册了 OnSubmit 语句。Determines whether the OnSubmit statement is registered with the Page object using the specified key.

IsOnSubmitStatementRegistered(Type, String)

确定 Page 对象是否使用指定的键和类型注册了 OnSubmit 语句。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

参数

type
Type

要搜索的 OnSubmit 语句的类型。The type of the OnSubmit statement to search for.

key
String

要搜索的 OnSubmit 语句的键。The key of the OnSubmit statement to search for.

返回

Boolean

如果已注册 OnSubmit 语句,则为 true;否则为 falsetrue if the OnSubmit statement is registered; otherwise, false.

例外

OnSubmit 语句的类型为 nullThe OnSubmit statement type is null.

示例

下面的代码示例演示方法的用法 IsOnSubmitStatementRegisteredThe following code example demonstrates the use of the IsOnSubmitStatementRegistered method. 使用注册了一个名 OnSubmitScript 为的脚本, Page 以便在提交该页的窗体时调用该脚本。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>

注解

在调用方法之前调用此方法 RegisterOnSubmitStatement ,以避免注册重复的语句。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. 例如,在使用 Page 实例访问资源时,可以指定 Page 类型。For instance, when using a Page instance to access the resource, you specify the Page type.

另请参阅

适用于

IsOnSubmitStatementRegistered(String)

确定 Page 对象是否使用指定键注册了 OnSubmit 语句。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

参数

key
String

要搜索的 OnSubmit 语句的键。The key of the OnSubmit statement to search for.

返回

Boolean

如果已注册 OnSubmit 语句,则为 true;否则为 falsetrue if the OnSubmit statement is registered; otherwise, false.

注解

在调用方法之前调用此方法 RegisterOnSubmitStatement ,以避免注册重复的 OnSubmit 语句。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.

此方法的重载 IsOnSubmitStatementRegistered 调用重载,该重载采用和将 key type 类型设置为对象的参数。 PageThis 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

另请参阅

适用于