473,624 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Viewstate for a control

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 the user may only change one
value. I know you can use viewstate to check if value has changed between
last postback and what is currently in the Text property (can I?). So, is
this correct syntax (focusing on the viewstate line)??

foreach (Control control in e.Item.Controls )
{
if(control is TextBox)
{
currenttextboxv alue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxv alue) {
//then user has changed value therefore build an update statement
string then later build a sql command
}
}
}

Nov 19 '05 #1
4 2588
TextBoxes don't use viewstate to maintain their values. Like many
"HTML-Like" controls the Web Forms Textbox controls simply POST their data
from the client to the server and then the server simply takes that value
and makes it become the default value of the control (using VALUE=) for the
trip from the server back to the client.

You can verify that TextBoxes don't use viewstate by enabling page tracing
and looking at the Control Tree section after doing a postback.

Anyway, you are probably better off just updating all the textbox values
rather than checking to see what has changed as checking to see what has
changed would take more resources than just updating the values.
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:57******** *************** ***********@mic rosoft.com...
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 the user may only change one
value. I know you can use viewstate to check if value has changed between
last postback and what is currently in the Text property (can I?). So, is
this correct syntax (focusing on the viewstate line)??

foreach (Control control in e.Item.Controls )
{
if(control is TextBox)
{
currenttextboxv alue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxv alue) {
//then user has changed value therefore build an update statement
string then later build a sql command
}
}
}

Nov 19 '05 #2
Just felt like overkill, to replace every value even if they just change one
character in a surname, but I see your point re server resource.

I have managed to get the original row from the datasource into the
ViewState, then check the viewstate row item value with the corresponding
textbox value. What do you think, does this still use lots of resource? (the
row (the fields my SP returns) has 29 items in it, therefore 29 textboxes on
form)

"Scott M." wrote:
TextBoxes don't use viewstate to maintain their values. Like many
"HTML-Like" controls the Web Forms Textbox controls simply POST their data
from the client to the server and then the server simply takes that value
and makes it become the default value of the control (using VALUE=) for the
trip from the server back to the client.

You can verify that TextBoxes don't use viewstate by enabling page tracing
and looking at the Control Tree section after doing a postback.

Anyway, you are probably better off just updating all the textbox values
rather than checking to see what has changed as checking to see what has
changed would take more resources than just updating the values.
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:57******** *************** ***********@mic rosoft.com...
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 the user may only change one
value. I know you can use viewstate to check if value has changed between
last postback and what is currently in the Text property (can I?). So, is
this correct syntax (focusing on the viewstate line)??

foreach (Control control in e.Item.Controls )
{
if(control is TextBox)
{
currenttextboxv alue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxv alue) {
//then user has changed value therefore build an update statement
string then later build a sql command
}
}
}


Nov 19 '05 #3
As I said, it would actually take less resources updating the 29 fields,
rather than checking the 29 fields to see which ones have changed.

It's more code to write the update statement (something you do once), but
less processing (something you'll do repeatedly).
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:1D******** *************** ***********@mic rosoft.com...
Just felt like overkill, to replace every value even if they just change
one
character in a surname, but I see your point re server resource.

I have managed to get the original row from the datasource into the
ViewState, then check the viewstate row item value with the corresponding
textbox value. What do you think, does this still use lots of resource?
(the
row (the fields my SP returns) has 29 items in it, therefore 29 textboxes
on
form)

"Scott M." wrote:
TextBoxes don't use viewstate to maintain their values. Like many
"HTML-Like" controls the Web Forms Textbox controls simply POST their
data
from the client to the server and then the server simply takes that value
and makes it become the default value of the control (using VALUE=) for
the
trip from the server back to the client.

You can verify that TextBoxes don't use viewstate by enabling page
tracing
and looking at the Control Tree section after doing a postback.

Anyway, you are probably better off just updating all the textbox values
rather than checking to see what has changed as checking to see what has
changed would take more resources than just updating the values.
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:57******** *************** ***********@mic rosoft.com...
> 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 the user may only change one
> value. I know you can use viewstate to check if value has changed
> between
> last postback and what is currently in the Text property (can I?). So,
> is
> this correct syntax (focusing on the viewstate line)??
>
> foreach (Control control in e.Item.Controls )
> {
> if(control is TextBox)
> {
> currenttextboxv alue = ((TextBox) control).Text;
> textboxid = control.ID;
> if (ViewState[textboxid].ToString() != currenttextboxv alue) {
> //then user has changed value therefore build an update statement
> string then later build a sql command
> }
> }
> }
>


Nov 19 '05 #4
OK. Thank you.

"Scott M." wrote:
As I said, it would actually take less resources updating the 29 fields,
rather than checking the 29 fields to see which ones have changed.

It's more code to write the update statement (something you do once), but
less processing (something you'll do repeatedly).
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:1D******** *************** ***********@mic rosoft.com...
Just felt like overkill, to replace every value even if they just change
one
character in a surname, but I see your point re server resource.

I have managed to get the original row from the datasource into the
ViewState, then check the viewstate row item value with the corresponding
textbox value. What do you think, does this still use lots of resource?
(the
row (the fields my SP returns) has 29 items in it, therefore 29 textboxes
on
form)

"Scott M." wrote:
TextBoxes don't use viewstate to maintain their values. Like many
"HTML-Like" controls the Web Forms Textbox controls simply POST their
data
from the client to the server and then the server simply takes that value
and makes it become the default value of the control (using VALUE=) for
the
trip from the server back to the client.

You can verify that TextBoxes don't use viewstate by enabling page
tracing
and looking at the Control Tree section after doing a postback.

Anyway, you are probably better off just updating all the textbox values
rather than checking to see what has changed as checking to see what has
changed would take more resources than just updating the values.
"louise raisbeck" <lo************ @discussions.mi crosoft.com> wrote in
message news:57******** *************** ***********@mic rosoft.com...
> 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 the user may only change one
> value. I know you can use viewstate to check if value has changed
> between
> last postback and what is currently in the Text property (can I?). So,
> is
> this correct syntax (focusing on the viewstate line)??
>
> foreach (Control control in e.Item.Controls )
> {
> if(control is TextBox)
> {
> currenttextboxv alue = ((TextBox) control).Text;
> textboxid = control.ID;
> if (ViewState[textboxid].ToString() != currenttextboxv alue) {
> //then user has changed value therefore build an update statement
> string then later build a sql command
> }
> }
> }
>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
21637
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
3
2637
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event and this causes control B to be created, when this is done the VIEWSTATE is lost for CONTROL B. In the EVENT that causes CONTROL B to be created I have to set
10
2257
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and disable the session state in Web.Config the VIEWSTATE variable is still maintained and stores some values. Can anyone tell what those values are for, i.e what other info is stored in VIEWSTATE other than the session ID and the control values ?
7
2039
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get them, or how do we get that value? I always have to set the ViewState("FirstName") = txtBox.text myself before a postback is done, otherwise, the value of ViewState("FirstName") is always empty; there doesn't seem to be a way to retrieve that...
5
7660
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:
10
3076
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web config does specify a machinekey setting: <machineKey validationKey="447C05E8B3A71401CC4CAE5513A7F1A3494A3618EE819316AAD1D58433F236A759D66FB4154500E01EB4E1BC1DE42046E2D652D391CB8367A1649438867A02EB"...
6
2058
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when page gets post back it gives following error Failed to load viewstate. The control tree into which viewstate is
2
4229
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set Visible = false on this detailsView. And rebound appropriate gridView. Then I press the button and I have exception: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save...
1
7589
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.
12
1913
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
0
8175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8336
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
8482
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7168
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...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4082
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...
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1487
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.