This documentation is archived and is not being maintained.

ClientScriptManager.RegisterHiddenField Method

Registers a hidden value with the Page object.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public void RegisterHiddenField (
	string hiddenFieldName,
	string hiddenFieldInitialValue
public void RegisterHiddenField (
	String hiddenFieldName, 
	String hiddenFieldInitialValue
public function RegisterHiddenField (
	hiddenFieldName : String, 
	hiddenFieldInitialValue : String
Not applicable.



The name of the hidden field to register.


The initial value of the field to register.

Exception typeCondition


hiddenFieldName is a null reference (Nothing in Visual Basic).

The RegisterHiddenField method creates a hidden <input> element on the rendered HTML page.

The following code example demonstrates the use of the RegisterArrayDeclaration and RegisterHiddenField methods. The example registers an array and a hidden value and defines the OnClick event of an <input> button to calculate the sum of two values of the array and the hidden value.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">
  public void Page_Load(Object sender, EventArgs e)
    // Define the array name and values.
    String arrName = "MyArray";
    String arrValue = "\"1\", \"2\", \"text\"";
    // Define the hidden field name and initial value.
    String hiddenName = "MyHiddenField";
    String hiddenValue = "3";
    // Define script name and type.
    String csname = "ConcatScript";
    Type cstype = this.GetType();
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Register the array with the Page class.
    cs.RegisterArrayDeclaration(arrName, arrValue);

    // Register the hidden field with the Page class.
    cs.RegisterHiddenField(hiddenName, hiddenValue);

    // Check to see if the  script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname))
      StringBuilder cstext = new StringBuilder();
      cstext.Append("<script type=\"text\"/javascript> function DoClick() {");
      cstext.Append("Form1.Message.value='Sum = ' + ");
      cstext.Append("(parseInt(" + arrName + "[0])+");
      cstext.Append("parseInt(" + arrName + "[1])+");
      cstext.Append("parseInt(" + Form1.Name + "." + hiddenName + ".value));} </");
      cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false);
<html xmlns="" >
    <title>ClientScriptManager Example</title>
     <form    id="Form1"
     <input type="text"
            id="Message" />
     <input type="button" 
            value="Run Script" />

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0