Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data in TextBox Not Updating 1

Status
Not open for further replies.

sunmorgus

Programmer
Nov 9, 2004
81
US
Ok, here is the skinny. I have a textbox on a webform (asp.net 2.0) that has it's text property set on load to data from a sqldatareader (I read the data into a string variable, then sent the text property equal to the string variable). This is working well, except for one problem, I want to be able to type over the data in that text box, and when I hit a submit button on the form, update the data in the database that was originally set at runtime (using a sqlcommand object and a stored procedure).

Basically this:
1)Form opens, text box has data in it from database (i.e. "Test")
2)I delete "Test" text from text box, and type in "Test2"
3)I hit the submit button, and through a sqlcommand object update the data on the database from "Test" to "Test2"

That is how I want it to work, but no matter what I try, all I get is the original data that got populated in the text box on load. If any of that made sense, could someone please help me figure out why the data won't update when I pre-populate it from the database? It works fine if I don't pre-populate first...
 
You are using a separate stored procedure for your update, right?

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Make sure that you are not loading the data again when you get a postback.

In your Page_Load event, include a conditional:

if (!this.IsPostBack) {
//Load Data
}

That Page_Load gets fired everytime the page is, well, loaded, not just the first time. Without the conditional, you may blow away the Text value that was entered with the original data.
 
OMG, thank you. I can't believe I missed that! I guess I am more of a newb than I thought! Hehe!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top