Page.RegisterOnSubmitStatement(String, String) Page.RegisterOnSubmitStatement(String, String) Page.RegisterOnSubmitStatement(String, String) Page.RegisterOnSubmitStatement(String, String) Method

定義

警告

此 API 現已淘汰。

允許網頁存取用戶端 OnSubmit 事件。Allows a page to access the client OnSubmit event. 指令碼應該為登錄於別處的用戶端程式碼之函式呼叫。The script should be a function call to client code registered elsewhere.

public:
 void RegisterOnSubmitStatement(System::String ^ key, System::String ^ script);
[System.Obsolete("The recommended alternative is ClientScript.RegisterOnSubmitStatement(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202")]
public void RegisterOnSubmitStatement (string key, string script);
member this.RegisterOnSubmitStatement : string * string -> unit
Public Sub RegisterOnSubmitStatement (key As String, script As String)

參數

key
String String String String

識別指令碼區塊的唯一索引鍵。Unique key that identifies a script block.

script
String String String String

要傳送到用戶端的用戶端指令碼。The client-side script to be sent to the client.

範例

下列程式碼範例將示範RegisterOnSubmitStatement如何使用來存取在按一下用戶端提交按鈕時回應的腳本。The following code example demonstrates using the RegisterOnSubmitStatement to access a script that responds when a client-side Submit button is clicked. 當此事件發生時,已註冊的 ECMAScript 程式碼會在用戶端上執行。When this event occurs, the registered ECMAScript code is executed on the client.

重要

這個範例有一個隱藏欄位,這是潛在的安全性威脅。This example has a hidden field, which is a potential security threat. 根據預設,您應該驗證隱藏欄位的值,就像是文字方塊的值一樣。By default, you should validate the value of a hidden field as you would the value of a text box. ASP.NET 網頁會驗證使用者輸入不包含腳本或 HTML 元素。ASP.NET Web pages validate that user input does not include script or HTML elements. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。For more information, see Script Exploits Overview.

void Page_Load(Object sender, EventArgs e) 
{ 
   String scriptString = "<script language=\"JavaScript\"> function doClick() {";
   scriptString += "document.write('<h4>' + myForm.myHiddenField.value+ '</h4>');}<";
   scriptString += "/" + "script>";
      
   RegisterHiddenField("myHiddenField", "Welcome to Microsoft!"); 
   
   RegisterOnSubmitStatement("submit", "document.write('<h4>Submit button clicked.</h4>')"); 
   
   RegisterStartupScript("startup", scriptString);
} 

     Dim scriptString As String = "<script language=""JavaScript""> function doClick() {"
scriptString += "document.write('<h4>' + myForm.myHiddenField.value+ '</h4>');}<"
scriptString += "/" + "script>"
   
RegisterHiddenField("myHiddenField", "Welcome to Microsoft!")

RegisterOnSubmitStatement("submit", "document.write('<h4>Submit button clicked.</h4>')")

RegisterStartupScript("startup", scriptString)

備註

RegisterOnSubmitStatement 方法已被取代。The RegisterOnSubmitStatement method has been deprecated. 在類別中使用RegisterOnSubmitStatement方法 ClientScriptManagerUse the RegisterOnSubmitStatement method in the ClientScriptManager class.

適用於

另請參閱