-
txtbox not updating
this is in asp.net but I'm using the vb codebehind page to code:
On the page load I use a datareader to populate the textboxes on my page. I let the user make changes then on a save click event I run an update. The value stays the same in the txtbox, even though I made changes to it. I debug thru and the value is indeed the same. Has anyone come across this problem?
-
Does the page get reloaded or refreshed in the meantime? Is AutoPostback set to True for the textbox?
-
To update the record, I'm going through a click event, so it looks like the page is being reloaded. The autopostback is set to false.
-
here's a more clearer picture of what is happending:
this is how I fill my textboxs on the page_load
Code:
Do While objDataReader.Read = True
txtBidId.Text = objDataReader("Bid_ID")
txtBuyerName.Text = objDataReader("Buyer_Name")
txtIntDisStartDate.Text = objDataReader("display_start_date")
txtBidOpenDate.Text = objDataReader("bid_date")
txtBidDesc.Text = objDataReader("bid_schedule_desc")
txtIntDisEndDate.Text = objDataReader("display_end_date")
then the user makes any changes they need and then on the save click event I have my update.
Code:
sqlCmd = "update pbss.pbss_bid_schedule "
sqlCmd = sqlCmd & "set bid_date= to_date('" & txtBidOpenDate.Text & "','MM/DD/YYYY')"
sqlCmd = sqlCmd & ",bid_status_code='" & Bid_Status & "'"
sqlCmd = sqlCmd & ",pre_bid_ind=0,bid_schedule_desc='" & txtBidDesc.Text & "'"
the problem I'm having is the textbox values are still holding the same values from when the datareader filled them up, even after changes have been made. I can see this when I debug
-
Is the Do While Read part within an if Not PostBack block? If it isn't then it will be reran at postback.
-
That was the problem. I was clicking the save button and it was going trough the page_load event first and then the click event. So I used a If Not Me.IsPostBack() Then to check. How come the click event goes through the page_load? Is there a way to avoid that? Now I have to click twice to get to my click event..
-
The click event forces the page to refresh, which then loads it again, and due to the way states work on webpages this causes the load event to fire. Luckily you have the IsPostBack function to see if its the first time or not.
-
any idea's as to why I have to click twice now to get to the click event?
-
I'm not sure but what I think it is because you are changing the values in the click event which doesn't fire until after teh page_load event, which means that it needs another page load to actually display the changes. Try changing the button's AutoPostBack prop to True or just set a flag in the click event and make the actual changes in the load event if IsPostBack=True.