ClientScriptManager.RegisterOnSubmitStatement メソッド
アセンブリ: System.Web (system.web.dll 内)
構文
Dim instance As ClientScriptManager Dim type As Type Dim key As String Dim script As String instance.RegisterOnSubmitStatement(type, key, script)
OnSubmit ステートメントは、そのキーと型で一意に識別されます。同じキーと型を持つステートメントは重複していると見なされます。同じ型とキーのペアを持つステートメントは、同じページに 1 つだけ登録できます。既に登録されているステートメントを登録しようとしても、重複したステートメントは作成されません。
IsOnSubmitStatementRegistered メソッドを呼び出して、任意のキーと型のペアを持つ OnSubmit ステートメントが既に登録されていないか確認し、スクリプトを不要に追加しようとする手間を省きます。
RegisterOnSubmitStatement メソッドの script パラメータには、複数のスクリプト コマンドを含めることができます。これらはセミコロン (;) で区切る必要があります。
RegisterOnSubmitStatement は、ページが送信される前に実行されるスクリプトを追加し、送信をキャンセルする機会を提供します。
HTML フォームと OnSubmit 属性の詳細については、W3C (World Wide Web Consortium) Web サイト () を参照してください。
RegisterOnSubmitStatement メソッドの使用方法を示すコード例を次に示します。
<%@ Page Language="VB" %> <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> <head> <title>ClientScriptManager Example</title> </head> <body> <form id="Form1" runat="server"> <input type="submit" value="Submit"> </form> </body> </html>
<%@ Page Language="C#"%> <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> <head> <title>ClientScriptManager Example</title> </head> <body> <form id="Form1" runat="server"> <input type="submit" value="Submit"> </form> </body> </html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ClientScriptManager.RegisterOnSubmitStatement メソッドのページへのリンク