Exercise Answers
Profile.PostCode = CType(FCLoginView.FindControl(“txtPostCode”), TextBox).Text Profile.Country = CType(FCLoginView.FindControl(“txtCountry”), TextBox).Text Profile.Mailings = CType(FCLoginView.FindControl(“chkMailing”), CheckBox).Checked Profile.Email = CType(FCLoginView.FindControl(“txtEmail”), TextBox).Text Profile.MemberName = CType(FCLoginView.FindControl(“txtAlias”), TextBox).Text Profile.Theme = CType(FCLoginView.FindControl(“ThemeList”),
DropDownList).SelectedValue
Dim DoB As TextBox = CType(FCLoginView.FindControl(“txtDoB”), TextBox) If DoB.Text <> “” Then
Profile.DateOfBirth = DateTime.Parse(DoB.Text)
End If
Server.Transfer(SiteMap.CurrentNode.Url)
End Sub
Note that you need to check that the text box is not empty (if you try to save with an empty text box, you’ll see an error page due to an exception).
4.Finally, add the following code to the DisplayProfileProperties() method:
Private Sub DisplayProfileProperties()
Dim NameBox As TextBox = CType(FCLoginView.FindControl(“txtName”), TextBox)
If Not (NameBox Is Nothing) Then
CType(FCLoginView.FindControl(“txtName”), TextBox).Text = Profile.Name
CType(FCLoginView.FindControl(“txtAddress”), TextBox).Text = Profile.Address
CType(FCLoginView.FindControl(“txtCity”), TextBox).Text = Profile.City
CType(FCLoginView.FindControl(“txtCounty”), TextBox).Text = Profile.County
CType(FCLoginView.FindControl(“txtPostCode”), TextBox).Text = Profile.PostCode
CType(FCLoginView.FindControl(“txtCountry”), TextBox).Text = Profile.Country
CType(FCLoginView.FindControl(“chkMailing”), CheckBox).Checked = _
Profile.Mailings
CType(FCLoginView.FindControl(“txtEmail”), TextBox).Text = Profile.Email
CType(FCLoginView.FindControl(“txtAlias”), TextBox).Text = Profile.MemberName
CType(FCLoginView.FindControl(“ThemeList”), DropDownList).SelectedValue = _
Profile.Theme
CType(FCLoginView.FindControl(“txtDoB”), TextBox).Text = _
Profile.DateOfBirth.ToShortDateString()
End If
End Sub
This code will convert the DateTime value stored in the user’s profile into its string representation so that it can be displayed on the screen. Because users are unlikely to know the exact time they were born, you can ignore the time part of the date — hence why you’ve used the ToShortDateString() instead of ToString() method. Once finished, you can test it out on the user of your choice. In Figure A-9, I’ve used Alan the Admin.