ClientScriptManager.RegisterOnSubmitStatement(Type, String, String) Método

Definición

Registra una instrucción OnSubmit con el objeto Page utilizando un tipo, una clave y un literal de script. La instrucción se ejecuta cuando se envía el objeto HtmlForm.

public:
 void RegisterOnSubmitStatement(Type ^ type, System::String ^ key, System::String ^ script);
public void RegisterOnSubmitStatement (Type type, string key, string script);
member this.RegisterOnSubmitStatement : Type * string * string -> unit
Public Sub RegisterOnSubmitStatement (type As Type, key As String, script As String)

Parámetros

type
Type

Tipo de la instrucción OnSubmit que se va a registrar.

key
String

Clave de la instrucción OnSubmit que se va a registrar.

script
String

Literal de script de la instrucción OnSubmit que se va a registrar.

Excepciones

type es null.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del RegisterOnSubmitStatement método .

<%@ 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>

Comentarios

Una instrucción OnSubmit se identifica de forma única por su clave y su tipo. Las instrucciones con la misma clave y tipo se consideran duplicados. Solo se puede registrar una instrucción con un tipo determinado y un par de claves con la página. Si se intenta registrar una instrucción que ya está registrada, no se creará un duplicado de la instrucción.

Llame al IsOnSubmitStatementRegistered método para determinar si una instrucción OnSubmit ya está registrada con una clave y un par de tipos dados y evitar que se intente agregar el script innecesariamente.

El script parámetro del RegisterOnSubmitStatement método puede contener varios comandos de script siempre y cuando estén delimitados correctamente con un punto y coma (;).

RegisterOnSubmitStatement agrega un script que se ejecuta antes de enviar la página y le ofrece la oportunidad de cancelar el envío.

Para obtener más información sobre los formularios HTML y el OnSubmit atributo , vea el sitio web de World Wide Web Consortium (W3C).

Se aplica a

Consulte también