I have created a web form with text boxes that are bound to a DataSet/DataView. I have created button to navigate up and down the recordset. That all works fine.
I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database.
When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command. For some reason, it will only get the text from a text box if the data was pulled the database. If I add/edit data, then the SQL command will have a blank spot where normally it would pull the text from the text box.
Any ideas would be GREATLY appreciated.
![]() |
0 |
![]() |
Please show us some code displaying how you get the TexBox values in your Update method.
Regards
Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
![]() |
0 |
![]() |
Hi,
When you populate the textboxes - do you check whether Page.IsPostback is true/false?
Until you post som code, I'm guessing you're not.
if (!IsPostBack) {
// Populate textboxes
}
else {
// It is a postback, the Save button
// shold have an .Click event to handle
// the new data
}
That help?
--
Tarjei
![]() |
0 |
![]() |
First, thank you for the quick responses. I will address each item below, including my code.
1 - No, I do not check to see if Page.IsPostback is True or False
2 - A few notes re: the code below:A - Originally, I just created a SQL string, DIMed a SQLCommand and then opened the connection, Executed the Query and closed the connection
B - When that did not work, I REMed out the connection/excution to just try to see what I was getting by posting the string into a text box. That is how I found out that it was not grabbing the text if it had been edited.
C - Again, this works fine if it grabs text that came from the database record. However, if I edit or add text to the text box, the text will not go into the string.I am new to VB .net and webforms, although I have extensive experience with VB6 and VBA. Is there something re: the order that the form processes the screen which is causing my app to clear the box BEFORE it reads the text that has been entered?
----------
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'Update any changes
'Insert code to create SQL UPDATE command (cmdEventsUpdate)
Dim strSQL, strPlan As String
'Dim cmdEventsUpdate As New SqlClient.SqlCommand(strSQL, cnEvents)
strPlan = txtLocation.Text
strSQL = "UPDATE Observed_Events SET Event_Plan = '" & strPlan & "' WHERE (Event_num = " & txtEvent.Text & ")"
txtSitelayout.Text = strSQL'cnEvents.Open()
'cmdEventsUpdate.ExecuteNonQuery()
'cnEvents.Close()
End Sub
![]() |
0 |
![]() |
gr8britton wrote:
1 - No, I do not check to see if Page.IsPostback is True or False
Well there's your culprit right there. You populate your Textboxes on every PostBack. This means that the values you get when trying to Update are always the ones you get from Db. Remember, Page_Load is always run. This is why you need to check for PostBack like suggested above:
Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)If Not IsPostBack Then
'DataBind your TextBoxes the first time and only then
End IfEnd Sub
This is all you need to do. When the User Clicks the update Button, it's a PostBack and no DataBinding will take place in Page_Load. Your Sub 'btnSave_Click' will take over and update your Data.
Regards
Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
![]() |
0 |
![]() |
Thank you for educating me on that. I had a feeling something was happening before I was populating my string. I will give this a shot and post the results.
![]() |
0 |
![]() |
Thank you for educating me on that. I had a feeling something was happening before I was populating my string.
I applied your suggestion and it works great. Thank you so much for help!
![]() |
0 |
![]() |