473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Retrieving Control Values From ViewState

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
2 1401
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Cosmas | last post by:
I've got a page which loads up a different user control into a placeholder control every time a button is clicked on the parent page. I use a statement like...
2
by: P. Gruenhagen | last post by:
I've written several UserControls that contain different versions of a form that users need to fill out. Depending on which role a user is logged in as, I load the appropriate UserControl and add...
4
by: louise raisbeck | last post by:
Hi I know there are many posts on this but cant seem to find simple answer. I have lots of text boxes in a datalist edittemplate control. i dont want to do an update statement for all of them, as...
7
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is important to note that the user control that hosts...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
2
by: Pipo | last post by:
Nobody knows how to get the values provided in the client can be read in the user-control? If have made a Web Custom Control with 2 textboxes and 1 dropdownlist. The user fills in my control (the...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
5
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.