472,121 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

Wrong textbox.text value

Hi all,

I hope someone can help me with the following problem in ASP.net.
I want to edit the information for a record in a database (MS Access).
On the page I placed several textboxes and dropdownlistboxes. In the
page_load the information from the database is loaded a dataset. With
the following command I place the info from the dataset in the boxes:

txtFirstName.Text = ds.Tables(0).Rows(0).Item("FirstName")

The user can make changes and click a button. In the button click event
a SQL command is created to update the database. The problem is that
when I read the textbox.text value it isn't the value the user entered
but the original value from the dataset (database).

I think it has something to do with the viewstate, but the things I
have tried didn't work. (VIEWSTATE = false for the page and/or boxes)

There is probably another solution possible with the dataset, but
because I'm learning ASP.net I wanted to try this.

Hope someone can help or point me in another direction.

Thanks,

Hans

Nov 19 '05 #1
5 2257
it could be the postback

are u setting this text box like below? without IsPostback check, the
text box will get assigned on every visit to the page.

if (!Page.IsPostback())
{
txtFirstName.Text = ds.Tables(0).Rows(0).Item("Fir*stName")
}

Nov 19 '05 #2
Make sure to wrap a "Not IsPostBack()" around the populating of the
textbox...just to make sure you aren't re-populting it before reading it in.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"ha***********@gmail.com" wrote:
Hi all,

I hope someone can help me with the following problem in ASP.net.
I want to edit the information for a record in a database (MS Access).
On the page I placed several textboxes and dropdownlistboxes. In the
page_load the information from the database is loaded a dataset. With
the following command I place the info from the dataset in the boxes:

txtFirstName.Text = ds.Tables(0).Rows(0).Item("FirstName")

The user can make changes and click a button. In the button click event
a SQL command is created to update the database. The problem is that
when I read the textbox.text value it isn't the value the user entered
but the original value from the dataset (database).

I think it has something to do with the viewstate, but the things I
have tried didn't work. (VIEWSTATE = false for the page and/or boxes)

There is probably another solution possible with the dataset, but
because I'm learning ASP.net I wanted to try this.

Hope someone can help or point me in another direction.

Thanks,

Hans

Nov 19 '05 #3
ha***********@gmail.com wrote:
Hi all,

I hope someone can help me with the following problem in ASP.net.
I want to edit the information for a record in a database (MS Access).
On the page I placed several textboxes and dropdownlistboxes. In the
page_load the information from the database is loaded a dataset. With
the following command I place the info from the dataset in the boxes:

txtFirstName.Text = ds.Tables(0).Rows(0).Item("FirstName")

The user can make changes and click a button. In the button click
event a SQL command is created to update the database. The problem is
that when I read the textbox.text value it isn't the value the user
entered but the original value from the dataset (database).

I think it has something to do with the viewstate, but the things I
have tried didn't work. (VIEWSTATE = false for the page and/or boxes)

There is probably another solution possible with the dataset, but
because I'm learning ASP.net I wanted to try this.

Hope someone can help or point me in another direction.

Thanks,

Hans


The page_load is executed every time, and before the click handler is executed.
So when the user changes the value and submits, you replace it with the
original value before the click handler tries to save the "new" value.

Solution:
either move the code to PreRender
and/or protect it with a test for "not IsPostBack"

Hans Kesting
Nov 19 '05 #4
Thanks for the fast replies! The IsPostBack check is missing, so ...

I will change and test it tomorrow and post back the result.

Thanks again,

Hans

Nov 19 '05 #5
I works! The IsPostBack check made it work. It's a shame that I didn't
find it myself, because I already used it on another page.

Thanks again to all of you!

Hans

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul M. Frazier, Ph.D. | last post: by
5 posts views Thread by Steve S | last post: by
22 posts views Thread by Tim | last post: by
reply views Thread by d.steininger | last post: by
reply views Thread by leo001 | last post: by

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.