473,372 Members | 811 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,372 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 2347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: tom | last post by:
Hello, I have an asp.net web application where I want people to register themselves. This takes them through a few pages with prev/next functionality. In one of the pages they provide a...
1
by: Paul M. Frazier, Ph.D. | last post by:
I am writing a user information update page and I populate the form on Page_Load with the current values of the user's name, etc. When I change the text in one of the textbox controls (e.g.,...
5
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
5
by: JollyK | last post by:
Hello all, I have always been having this issue and wondering what the solution is. When I set the enableviewstate property to false for a textbox, the textbox always retains its value after a...
0
by: jason | last post by:
Hello everyone. I am trying to write some custom command events into a DataGrid. The command that is currently giving me trouble is an "Add" custom command in the footer of a template column. ...
22
by: Tim | last post by:
Hi A while ago I got some help in writing a mock console. The idea was to write a VB app that contained a textbox, then run a process from within the app and redirect the stdout to the textbox. ...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
0
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
2
by: lordnaickol | last post by:
Hi everybody! I'm trying to develop my first VB.NET application, but I have a big problem. I have to fill some textboxes with some info comming form a plain text file, but when I assign the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.