This documentation is archived and is not being maintained.

Page.RegisterHiddenField Method

Allows server controls to automatically register a hidden field on the form. The field will be sent to the Page when the HtmlForm server control is rendered.

[Visual Basic]
Public Overridable Sub RegisterHiddenField( _
   ByVal hiddenFieldName As String, _
   ByVal hiddenFieldInitialValue As String _
)
[C#]
public virtual void RegisterHiddenField(
 string hiddenFieldName,
 string hiddenFieldInitialValue
);
[C++]
public: virtual void RegisterHiddenField(
 String* hiddenFieldName,
 String* hiddenFieldInitialValue
);
[JScript]
public function RegisterHiddenField(
   hiddenFieldName : String,
 hiddenFieldInitialValue : String
);

Parameters

hiddenFieldName
The unique name of the hidden field to be rendered.
hiddenFieldInitialValue
The value to be emitted in the hidden form.

Example

[Visual Basic, C#] The following example uses the RegisterHiddenField method to help create JavaSCript code that is passed to the requesting browser. The name of the hidden field is set to myHiddenField and its value is set to "Welcome to Microsoft .NET!" The RegisterStartupScript method calls the myHiddenField value when the user clicks a button on the page.

[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: