ASP NET Edit a Text Box using VB.NET
As my skills with ASP.NET increase I look for first the simple and later the elegant way to accomplish a task.
My interest was to fire a value from a data drop down list box, populate text boxes and then Edit the result in the text box. Editing a text box seems trivial and like anything else in life – it is once you know how!
The following is offered to those just starting out with ASP.NET and would like to Edit a textbox. An example of one test box is given. You can build upon this as you wish or use the elegant solutions offered by Rick and Bonnie.
You can use C sharp if you wish - my example is what I used to get the puppy to work.
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim userID As String = ddlUsersID.SelectedItem.Value
UpdateUser(userID, txtPhoneExt.Text)
End sub
Sub UpdateUser(ByVal userID As String, ByVal PhoneExt As String)
Dim sql As String = "UPDATE UserInfo SET PhoneExt=@PhoneExt WHERE userID=@userID"
Dim cmd As New SqlCommand(sql, SqlConnection1)
cmd.Parameters.Add("@PhoneExt", PhoneExt)
cmd.Parameters.Add("@UserID", userID)
If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
cmd.ExecuteNonQuery()
End Sub
Tom