VIEW STATE
Use the ViewState property to save data in a hidden field on a page. Because ViewState stores data on the page, it is limited to
items that can be serialized. If you want to store more complex items in ViewState, you must convert the items to and from
a string
For example, the following code adds text from a text box to cells in a table on the page. Because you can't store objects
directly in ViewState, you must store the strings in the butAdd_Click procedure and then create the table row controls from
the strings, as shown in the Page_PreRender procedure.
// This executes just before the page is displayed.
// so it exhibits the affects of the button clicks.
private void Page_PreRender(object sender, EventArgs e)
{
// Create a new row object
TableRow rowNew = new TableRow();
// Add row to the table
tblViewState.Rows.Add(rowNew);
// For each item in the ViewState
foreach (StateItem Item in ViewState.Values)
{
// Create a new table cell
TableCell celNew = new TableCell();
// Set cell text.
celNew.Text = Item.Value.ToString();
// Add cell to row
rowNew.Cells.Add(celNew);
// Create a new row every four cells.
if (rowNew.Cells.Count > 3)
{
rowNew = new TableRow();
tblViewState.Rows.add(rowNew);
}
}
}
ASP.NET hashses the hidden data stored on the pages so that it is not intelligible to users.