Visual Basic .NET » Visual Basic .NET General Discussion
C# .NET 2.0 -- Roman --


Is there a way to revert the contents of a textbox to a preceding value after postback has been made?

How do I save the contents of a textbox between postbacks?

Thanks in advance

-- JoeEnos --


One way would be to use Session variables, assuming the logic is simple enough, and you don't have too many fields to save:

For example, if you only want to store a single value, you could do something like:
Session
= txtTextBox.Text;

If you want to store multiple previous values, you could make that session value a collection, probably an ArrayList. For example:
if (Session
!= null)
{
ArrayList al = (ArrayList)Session
;
al.Add(txtTextBox.Text);
Session
= al;
}
When you want to retrieve the most recent value, you can use something like:
if (Session
!= null)
{
ArrayList al = (ArrayList)Session
;
string lastValue = al.Items
.ToString();
}

This all assumes using System.Collections;

-- andyb --


If you want to maintain the information after postback on a single page I would recommend using ViewState. It works the same as Joe uses Session above. If you want to maintain the value across multiple pages,
Session is what you need to use.

-- andyb --


If you want to maintain the information after postback on a single page I would recommend using ViewState. It works the same as Joe uses Session above. If you want to maintain the value across multiple pages,
Session is what you need to use.

[Submit Comment]Home