This documentation is archived and is not being maintained.

Page.RegisterOnSubmitStatement Method

Allows a page to access the client OnSubmit event. The script should be a function call to client code registered elsewhere.

[Visual Basic]
Public Sub RegisterOnSubmitStatement( _
   ByVal key As String, _
   ByVal script As String _
)
[C#]
public void RegisterOnSubmitStatement(
 string key,
 string script
);
[C++]
public: void RegisterOnSubmitStatement(
 String* key,
 String* script
);
[JScript]
public function RegisterOnSubmitStatement(
   key : String,
 script : String
);

Parameters

key
Unique key that identifies a script block.
script
The client-side script to be sent to the client.

Example

[Visual Basic, C#] The following example demonstrates using the RegisterOnSubmitStatement to access a script that responds when a client-side submit button is clicked. When this event occurs, the registered ECMAScript code is executed on the client.

[Visual Basic] 

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

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

RegisterStartupScript("startup", scriptString)

[C#] 
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 .NET!"); 
   
   RegisterOnSubmitStatement("submit", "document.write('<h4>Submit button clicked.</h4>')"); 
   
   RegisterStartupScript("startup", scriptString);
} 

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Page Class | Page Members | System.Web.UI Namespace

Show: