473,699 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)ViewSt ate["myTextBoxI d"];

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 1406
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
RaisePostDataCh anedEvent, this method then actually fires the onchanged
event.

-- bruce (sqlwork.com)
"epigram" <no****@spammy. com> wrote in message
news:1118071293 .c601a0e77e7e90 df7714bce647a89 840@bubbanews.. .
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)ViewSt ate["myTextBoxI d"];

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.c om> wrote in message
news:OD******** ******@tk2msftn gp13.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
RaisePostDataCh anedEvent, this method then actually fires the onchanged
event.

-- bruce (sqlwork.com)
"epigram" <no****@spammy. com> wrote in message
news:1118071293 .c601a0e77e7e90 df7714bce647a89 840@bubbanews.. .
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)ViewSt ate["myTextBoxI d"];

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
3355
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 Me.plcTabViews.Controls.Add(LoadControl("test.ascx")). There are up to 30 possibilities which are decided by CASE statements and keeps one from loading up onto another. However, I'm running into a unique error... Failed to load viewstate. The control tree into which viewstate is...
5
7662
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 protected member 'System.Web.UI.Control.ViewState' via a qualifier of type 'System.Web.UI.Control'; the qualifier must be of type 'ASP.ItemOrderGrid' (or derived from it) Source Error:
1
5442
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 fragment of a very simple page that I wrote that will drill down into the displayed item. The result is to be display on the same page so that the user can keep on drilling down:
2
3952
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 has changed. How can I retrieve a control's previous value from the ViewState? I know that I could save the control's previous value in a session variable, reretrieve it's value from the db, etc. But it would appear the control's previous value...
7
2995
by: Shimon Sim | last post by:
I have a custom composite control I have following property
5
5978
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 event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset): Public Class DatePicker2...
4
3926
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 viewstate. I had created 4 methods to Add/Remove my special dates in viewstate. Up to here all seems perfect, but how do I used it in prerender event for my new calendar control.
1
7593
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 usercontrol is a button and a label. Everytime the button is clicked a counter which is stored in the viewstate is increased and displayed in the label.
1
1641
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; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.