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

Définition

Inscrit une instruction OnSubmit avec l'objet Page à l'aide d'un type, d'une clé et d'un littéral de script. L'instruction s'exécute lorsque le HtmlForm est envoyé.

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)

Paramètres

type
Type

Type de l'instruction OnSubmit à inscrire.

key
String

Clé de l'instruction OnSubmit à inscrire.

script
String

Littéral de script de l'instruction OnSubmit à inscrire.

Exceptions

type a la valeur null.

Exemples

L’exemple de code suivant illustre l’utilisation de la RegisterOnSubmitStatement méthode .

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

Remarques

Une instruction OnSubmit est identifiée de manière unique par sa clé et son type. Les instructions avec la même clé et le même type sont considérées comme des doublons. Une seule instruction avec un type et une paire de clés donnés peut être inscrite auprès de la page. La tentative d’inscription d’une instruction déjà inscrite ne crée pas de doublon de l’instruction.

Appelez la IsOnSubmitStatementRegistered méthode pour déterminer si une instruction OnSubmit est déjà inscrite avec une paire de clé et de type donnée et évitez de tenter inutilement d’ajouter le script.

Le script paramètre de la RegisterOnSubmitStatement méthode peut contenir plusieurs commandes de script tant qu’elles sont correctement délimitées par un point-virgule (;).

ajoute RegisterOnSubmitStatement un script qui est exécuté avant l’envoi de la page et vous donne la possibilité d’annuler la soumission.

Pour plus d’informations sur les formulaires HTML et l’attributOnSubmit, consultez le site Web W3C (World Wide Web Consortium).

S’applique à

Voir aussi