AWehrstedt
Programmer
I'm pretty new to the object oriented programming world and ran into an issue this morning..hope somebody can help.
I've created a custom class call User which handles such methods as "getting user details", "save" and "update". The class has properties for first name, last name, email address, etc..
When I go to the web form that I created and pass a user ID into the query string the page calls the get details method of the class to populate the text boxes on the form. This all works great. However, when I change any of the textboxes and then call the update I see that all of the textboxes text properties are still set to properties from the class (i.e. even though I changed Jim to Jims on the screen the text property in the code behind still shows Jim). Everything is ok when inserting a new user, it only seems to happen after the textboxes have been set to the properties of the class from calling the get details method. Anybody have an idea?
My code is as follows:
On Form Load: (this portion works)
Dim user As User
user = New User
user.GetDetails(conn, Request.Params("userid"))
txtFirstName.Text = user.FirstName
txtLastName.Text = user.LastName
txtEmailAddress.Text = user.EmailAddress
txtPassword.Text = user.Password
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim user As User
If Request.Params("userid") = "" Then
'new user (New user works fine)
user = New User(txtFirstName.Text, txtLastName.Text, txtPassword.Text, txtEmailAddress.Text, chkActive.Checked)
user.Save(conn)
Else
'update existing user
user = New User
user.GetDetails(conn, Request.Params("userid"))
user.FirstName = txtFirstName.Text (This is where the text property is the old value instead of the value I changed on the screen)
user.LastName = txtLastName.Text
user.EmailAddress = txtEmailAddress.Text
user.Password = txtPassword.Text
user.Update(conn, Request.Params("userid"))
End If
End Sub
I've created a custom class call User which handles such methods as "getting user details", "save" and "update". The class has properties for first name, last name, email address, etc..
When I go to the web form that I created and pass a user ID into the query string the page calls the get details method of the class to populate the text boxes on the form. This all works great. However, when I change any of the textboxes and then call the update I see that all of the textboxes text properties are still set to properties from the class (i.e. even though I changed Jim to Jims on the screen the text property in the code behind still shows Jim). Everything is ok when inserting a new user, it only seems to happen after the textboxes have been set to the properties of the class from calling the get details method. Anybody have an idea?
My code is as follows:
On Form Load: (this portion works)
Dim user As User
user = New User
user.GetDetails(conn, Request.Params("userid"))
txtFirstName.Text = user.FirstName
txtLastName.Text = user.LastName
txtEmailAddress.Text = user.EmailAddress
txtPassword.Text = user.Password
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim user As User
If Request.Params("userid") = "" Then
'new user (New user works fine)
user = New User(txtFirstName.Text, txtLastName.Text, txtPassword.Text, txtEmailAddress.Text, chkActive.Checked)
user.Save(conn)
Else
'update existing user
user = New User
user.GetDetails(conn, Request.Params("userid"))
user.FirstName = txtFirstName.Text (This is where the text property is the old value instead of the value I changed on the screen)
user.LastName = txtLastName.Text
user.EmailAddress = txtEmailAddress.Text
user.Password = txtPassword.Text
user.Update(conn, Request.Params("userid"))
End If
End Sub