HiddenField Control
Hidden fields are a common trick of the HTML web developer’s trade for carrying information within a page when you do not want that information to be visible to the user—that is, the hidden field provides a way to store state information in the page. For example, you might want to keep track of whether a form on the page has been completed, has been saved as a draft, or is being edited for the first time.
Often, an easier and more elegant way to accomplish this task is to use one of the state mechanisms provided by the .NET Framework (see Chapter 6 for a complete discussion of state). However, sometimes this is impossible, perhaps for performance, bandwidth, or security reasons. (Performance and bandwidth are mostly two sides of the same coin.)
In HTML pages, you might use something such as the following code snippet to implement a hidden field:
<input type="hidden" id="FormStatus" value="Draft Saved">
Indeed, ASP.NET uses a hidden field to implement view state. You can see this by examining the source that is rendered to the browser, via the View → Source menu command in Internet Explorer. (Other browsers have analogous commands.) You will see something similar to the following, where the value attribute encodes all the information saved in view state:
<input type="hidden" name="_ _VIEWSTATE" value="/wEPDwUJL0CHlBR...YfL+BDX7xhMw=" />
To reap the benefits of server-side processing, you can use an ASP.NET HiddenField control to generate these hidden fields for use ...