Viewstate for a control

G

Guest

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
}
}
}
 
S

Scott M.

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.
 
G

Guest

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. said:
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 said:
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
}
}
}
 
S

Scott M.

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 said:
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. said:
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 said:
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
}
}
}
 
G

Guest

OK. Thank you.

Scott M. said:
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 said:
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. said:
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.


message 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
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top