Retrieving Control Values From ViewState

J

jupitermoonbeam

Hi,

I wondered if anyone can help. I have scowered the web and found
absolutely nothing that relates to my particular problem and I am
pulling my hair out.

Basically, I have a scenario where I need to retrieve the previous
value of a control (a text box) from the ViewState and compare it
directly with the new value. I know there is the OnChange events etc.
etc. but for this particular scenario the OnChange event doesn't always
fire.

Basically I need to keep a track of changes over several posts to
determine wether a change is a hard change or a soft change. This is
difficult to explain but has to do with a form which has an onChange
event which may, through it's actions nuke the change.

Here's an example:
I have a drop down which when changed updates another field. If they
hit the drop FIRST I need the field to change. The problem is that
someone could change the original field first, then click the drop
down, in this instance I need to preserve their values. Now to make it
more complex it all depends on the original values as to wether they
should be overwritten or not (as some options change the state more
dramatically).

The solution to this is to read from the viewstate and interogate it
for the original value of the controls. So basically what I want to do
is:

string controlOriginalValue = ViewState["Control.Text"]
string controlsNewValue = Control.Text

Can anyone help? Whenever I try to interrogate the ViewState for my
control it always has a count of 0. I have set EnableViewState to True
but still nothing is happening.

I am using ASP.NET 2.0.
 
G

Guest

if you want to do this on the client side, you can defaultValue property to
retrieve the value of the textbox when the page was loaded.

- Augustin
 
G

Guest

I am not sure if this is possible. Stateitem object has a 'IsDirty' flag that
indicates if the value if modified or not. i couldn't find any property that
lets us iterate through it's values. Even if it is possible (i dont think it
will be possbile), this might not be a recommended approach, i guess.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top