By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

Retrieving Control Values From ViewState

P: n/a
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.

Aug 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"ju*************@googlemail.com" wrote:
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.

Aug 11 '06 #2

P: n/a
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.
"ju*************@googlemail.com" wrote:
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.

Aug 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.