You have a page with a state
whose value the page needs to remember
postbacks to determine how the page should
RegisterHiddenField method of
to create a hidden text field in the rendered page.
Nothing special is required in the
Instead, in the code-behind class for the page, use the .NET language
of your choice to:
Programmatically insert a hidden text field into the form using the
RegisterHiddenField method of the
Use this field to store the value of the state you wish to preserve
Access the hidden text field on subsequent submissions of the page to the server.
Figure 6-3 shows the output of a simple form that
preserves the page state using a hidden field. Clicking the Prev/Next
buttons decrements/increments the value in the hidden field by one.
Example 6-11 shows the
file that produces the form. Example 6-12
and Example 6-13 show the companion VB and C#
code-behind files that demonstrate how to access the application
Figure 6-3. Maintaining page state with a hidden field
An approach we favor for remembering the current state of a value
postbacks to the server involves
programmatically inserting one or more hidden text fields into a
A similar technique is commonly used by classic ASP developers, who ...