ClientScriptManager.RegisterOnSubmitStatement(Type, String, String) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
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)
Parametri
- type
- Type
Tipo dell'istruzione OnSubmit da registrare.
- key
- String
Chiave dell'istruzione OnSubmit da registrare.
- script
- String
Valore letterale script dell'istruzione OnSubmit da registrare.
Eccezioni
type è null.
Esempio
Nell'esempio di codice seguente viene illustrato l'uso del RegisterOnSubmitStatement metodo .
<%@ 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>
Commenti
Un'istruzione OnSubmit viene identificata in modo univoco dalla chiave e dal relativo tipo. Le istruzioni con la stessa chiave e tipo sono considerate duplicati. Con la pagina è possibile registrare una sola istruzione con un tipo e una coppia di chiavi specificati. Se si tenta di registrare un'istruzione già registrata, non verrà creato un duplicato dell'istruzione .
Chiamare il IsOnSubmitStatementRegistered metodo per determinare se un'istruzione OnSubmit è già registrata con una determinata coppia di chiavi e tipi ed evitare inutilmente di tentare di aggiungere lo script.
Il script parametro del RegisterOnSubmitStatement metodo può contenere più comandi di script, purché siano delimitati correttamente da un punto e virgola (;).
RegisterOnSubmitStatement Aggiunge uno script eseguito prima dell'invio della pagina e consente di annullare l'invio.
Per altre informazioni sui moduli HTML e sull'attributoOnSubmit, vedere il sito Web World Wide Web Consortium (W3C).