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

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)
{
currenttextboxvalue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxvalue) {
//then user has changed value therefore build an update statement
string then later build a sql command
}
}
}

Nov 19 '05 #1
4 2579
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.microsoft.com> wrote in
message news:57**********************************@microsof t.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)
{
currenttextboxvalue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxvalue) {
//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.microsoft.com> wrote in
message news:57**********************************@microsof t.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)
{
currenttextboxvalue = ((TextBox) control).Text;
textboxid = control.ID;
if (ViewState[textboxid].ToString() != currenttextboxvalue) {
//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.microsoft.com> wrote in
message news:1D**********************************@microsof t.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.microsoft.com> wrote in
message news:57**********************************@microsof t.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)
> {
> currenttextboxvalue = ((TextBox) control).Text;
> textboxid = control.ID;
> if (ViewState[textboxid].ToString() != currenttextboxvalue) {
> //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.microsoft.com> wrote in
message news:1D**********************************@microsof t.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.microsoft.com> wrote in
message news:57**********************************@microsof t.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)
> {
> currenttextboxvalue = ((TextBox) control).Text;
> textboxid = control.ID;
> if (ViewState[textboxid].ToString() != currenttextboxvalue) {
> //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
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...
3
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...
10
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...
7
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...
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...
10
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...
6
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...
2
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...
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...
12
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
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
0
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...

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.