473,395 Members | 1,972 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,395 software developers and data experts.

retrive control from ViewState

I've tried asking this question several times and have received many good
answers, but ones that don't quite answer my question. This leads me to
believe that I am trying to do something very awkward or I don't know how to
pose the question correctly. Let me try again. I appreciate any input!
:-)

I have an asp.net web form with a TextBox control and a submit button. The
TextBox control's text property is set on the server before it is first
displayed to the user. When the form is posted back, because of the user
clicking the submit button, I am trying to determine what the value of the
TextBox control's text property was originally set to so that I can manually
compare it to what the text property is currently set to. I know I can
setup an event handler to capture the TextBox's text change event, but I
don't want to do that. I thought I could obtain the TextBox control out of
the ViewState. I tried doing this, in my button click event handler, with
code such as:

TextBox tbxSaved = (TextBox)ViewState["myTextBoxId"];

where myTextBoxId is the value of the id attribute of the TextBox control on
the form. It comes back as <undefined value>.

If you want the rest of the story here I've actually got several TextBox
controls on my form. Depending on which ones change I will have to execute
different db updates. It seems odd to respond to text change events for all
these controls and maybe set some dirty flags for each control and determine
later (in some other asp.net page event I suppose) which controls had
changed and determine my course of action. What I want to do is in the
button click event handler manually determine which controls have changed
and determine my course of action all from within this handler. The need I
have seems very routine, so clearly there is a easy way to handle this. It
just currently escapes me.

Any help would be much appreciated! Thanks!
Nov 19 '05 #1
3 1382
you have to capture the original text from viewstate before LoadPostData
event fires. when the postback data method is called by the framework the
text value (and viewstate) are updated to the new value.

note: when the framework calls a LoadPostData, the control returns whether
to fire the on changed event. the framework uses this return value, to know
whether to fire the onchanged event (the control does not track this). for
controls whose LoadPostData returns true, it later calls their
RaisePostDataChanedEvent, this method then actually fires the onchanged
event.

-- bruce (sqlwork.com)
"epigram" <no****@spammy.com> wrote in message
news:1118071293.c601a0e77e7e90df7714bce647a89840@b ubbanews...
I've tried asking this question several times and have received many good
answers, but ones that don't quite answer my question. This leads me to
believe that I am trying to do something very awkward or I don't know how
to pose the question correctly. Let me try again. I appreciate any
input! :-)

I have an asp.net web form with a TextBox control and a submit button.
The TextBox control's text property is set on the server before it is
first displayed to the user. When the form is posted back, because of the
user clicking the submit button, I am trying to determine what the value
of the TextBox control's text property was originally set to so that I can
manually compare it to what the text property is currently set to. I know
I can setup an event handler to capture the TextBox's text change event,
but I don't want to do that. I thought I could obtain the TextBox control
out of the ViewState. I tried doing this, in my button click event
handler, with code such as:

TextBox tbxSaved = (TextBox)ViewState["myTextBoxId"];

where myTextBoxId is the value of the id attribute of the TextBox control
on the form. It comes back as <undefined value>.

If you want the rest of the story here I've actually got several TextBox
controls on my form. Depending on which ones change I will have to
execute different db updates. It seems odd to respond to text change
events for all these controls and maybe set some dirty flags for each
control and determine later (in some other asp.net page event I suppose)
which controls had changed and determine my course of action. What I want
to do is in the button click event handler manually determine which
controls have changed and determine my course of action all from within
this handler. The need I have seems very routine, so clearly there is a
easy way to handle this. It just currently escapes me.

Any help would be much appreciated! Thanks!

Nov 19 '05 #2
What is the best practice for trying to deal with the particular scenario I
have described below?
"Bruce Barker" <br******************@safeco.com> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
you have to capture the original text from viewstate before LoadPostData
event fires. when the postback data method is called by the framework the
text value (and viewstate) are updated to the new value.

note: when the framework calls a LoadPostData, the control returns whether
to fire the on changed event. the framework uses this return value, to
know whether to fire the onchanged event (the control does not track
this). for controls whose LoadPostData returns true, it later calls their
RaisePostDataChanedEvent, this method then actually fires the onchanged
event.

-- bruce (sqlwork.com)
"epigram" <no****@spammy.com> wrote in message
news:1118071293.c601a0e77e7e90df7714bce647a89840@b ubbanews...
I've tried asking this question several times and have received many good
answers, but ones that don't quite answer my question. This leads me to
believe that I am trying to do something very awkward or I don't know how
to pose the question correctly. Let me try again. I appreciate any
input! :-)

I have an asp.net web form with a TextBox control and a submit button.
The TextBox control's text property is set on the server before it is
first displayed to the user. When the form is posted back, because of
the user clicking the submit button, I am trying to determine what the
value of the TextBox control's text property was originally set to so
that I can manually compare it to what the text property is currently set
to. I know I can setup an event handler to capture the TextBox's text
change event, but I don't want to do that. I thought I could obtain the
TextBox control out of the ViewState. I tried doing this, in my button
click event handler, with code such as:

TextBox tbxSaved = (TextBox)ViewState["myTextBoxId"];

where myTextBoxId is the value of the id attribute of the TextBox control
on the form. It comes back as <undefined value>.

If you want the rest of the story here I've actually got several TextBox
controls on my form. Depending on which ones change I will have to
execute different db updates. It seems odd to respond to text change
events for all these controls and maybe set some dirty flags for each
control and determine later (in some other asp.net page event I suppose)
which controls had changed and determine my course of action. What I
want to do is in the button click event handler manually determine which
controls have changed and determine my course of action all from within
this handler. The need I have seems very routine, so clearly there is a
easy way to handle this. It just currently escapes me.

Any help would be much appreciated! Thanks!


Nov 19 '05 #3
epigram,

LoadPostData is the correct way to do it, but the easiest way is to
just throw another entry into the viewstate to hold the old value. For
example, when you populate the textbox.Text property on the server,
just add another entry to the ViewState called OLD_VALUE. Upon
postback, retrive OLD_VALUE and compare it to textbox.Text.

Not the absolute best solution, but a very easy practicle one.

sayed

Nov 19 '05 #4

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...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
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...
4
by: rushikesh.joshi | last post by:
Hi All, I want to create custom control by using Web.UI.WebControls.Calendar, in which I want to set few days with different color. I had created two property to set the color and storing in...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
1
by: ganesh22 | last post by:
Hi, Here the below code is for dynamically creating textboxs, its creating fine but after user enters some values in textboxs how can i retrive that values? using System; using System.Data;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.