Textbox Losing Changes to Text on "Save"

I have a web form that is designed to take data from the user and store it in an SQL Database. The problem that I am having is that when I write out the SQL string to update the data to the database, the textbox.text property only shows the old value, and not the new value.

Here is the code where I write out the SQL String.
 Dim strSQL As String = "Update tblItem SET ItemDesc = '" & textbox.text & "' WHERE PDCode = '" & lblPDCode.Text & "'"
BluAvi8Asked:
Who is Participating?
 
sanjeewajConnect With a Mentor Commented:
Bit of addtional thought on pwrBall's comment:

It appears that the data is loaded in the Page_Load and display in the UI.  However you save the data in a event handler such as a button click.  Since the Page_Load happens before click event, you always load the values to the UI from previous values.  Potentially you are saving back the old values.

A more safer place to load the data in such case is Page_PreRender.  At this stage all event handling and saving has finished and if you load data from the DB now, it is going to be the new values.

If this does not answer could you attach your code?
Sanjeewa Jayasinghe
0
 
pwrBallCommented:
Check for Postback when loading the page and the fill the textbox with the old value
If Not Page.IsPostBack Then
fill the field with old data
0
All Courses

From novice to tech pro — start learning today.