Wrong textbox.text value

H

hans.bonefaas

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
 
G

Guest

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

sreejith.ram

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")
}
 
H

Hans Kesting

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
 
H

hans.bonefaas

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
 
H

hans.bonefaas

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
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top