Udostępnij za pośrednictwem


HiddenField Web Server Control Overview

The HiddenField control provides you with a way to store information in the page without displaying it. For example, you might store a user-preference setting in a HiddenField control so that it can be read in client script. To put information into a HiddenField control, you set its Value property to the value you want to store between postbacks.

This topic contains:

  • Features

  • Background

  • Class Reference

Features

You can use the HiddenField control to:

  • Store data in a hidden field on a page.

  • Detect when data stored in the hidden field has changed between postbacks.

Back to top

Background

The information in a HiddenField control is not displayed when the browser renders the page. However, it can be read and set in client script. When the page is posted back, the contents of the HiddenField control, which includes any changes made in client script, are available in server code.

Note

Although the information in a hidden field is not displayed, users can see the contents of the control by viewing the page's source. Do not store sensitive information in a HiddenField control, such as user IDs, passwords, or credit card information.

Detecting Changed Data

The value of a HiddenField control can be changed before the page is posted back to the server. This might occur because you are using the hidden field to share information between server code and client script, and client script has updated the value of the control.

To help you detect changes to data in the control, the HiddenField control raises a ValueChanged event if the value of the control changes between postbacks. You can handle this event to determine whether a value has changed.

Class Reference

The following table lists the classes that relate to the HiddenField control.

Member

Description

HiddenField

The main class for the control.

Back to top

See Also

Concepts

ASP.NET State Management Overview