Link to home
Start Free TrialLog in
Avatar of M.L. Martin
M.L. MartinFlag for United States of America

asked on

Error customizing CreateUserWizard control

In the following code I am recieving these errors. I am atemmpting to do the impossible as it seems now and that is gather additiaonal user data while creating a new user utilizing the CreateUserWizard control. I was able to locate the following code and I think my process will work if I can correct these errors. I have place arrows where I have the bad syntax or code. Can anyone tell me how or what I should change the code to. Please provide the full code or syntax if you can help. Thanks in advance.

Errors
1. 'ProviderUserKey' is not a member of 'System.Web.Security.Membership'

2. 'System.Web.Security.MembershipUser' cannot be converted to 'System.Web.Security.Membership'


Partial Class registration
    Inherits System.Web.UI.Page
    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
        ' Get the UserId of the just-added user
---->  Dim newUser As Membership = Membership.GetUser(CreateUserWizard1.UserName)
---->   Dim newUserId As Guid = DirectCast(newUser.ProviderUserKey, Guid)

        'Get Profile Data Entered by user in CUW control

        Dim FirstName As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"), TextBox).Text
        Dim LastName As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"), TextBox).Text

        ' Insert a new record into User_Profile

        ' Get your Connection String from the web.config. MembershipConnectionString is the name I have in my web.config
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("MembershipConnectionString").ConnectionString

        Dim insertSql As String = "INSERT INTO User_Profile(UserId,FirstName, LastName) VALUES(@UserId, @FirstName, @LastName)"
        Using myConnection As New Data.SqlClient.SqlConnection(connectionString)
            myConnection.Open()
            Dim myCommand As New Data.SqlClient.SqlCommand(insertSql, myConnection)
            myCommand.Parameters.AddWithValue("@UserId", newUserId)
            myCommand.Parameters.AddWithValue("@FirstName", FirstName)
            myCommand.Parameters.AddWithValue("@LastName", LastName)

            myCommand.ExecuteNonQuery()
            myConnection.Close()
        End Using
    End Sub

   

End Class
ASKER CERTIFIED SOLUTION
Avatar of JayFromPep
JayFromPep
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M.L. Martin

ASKER

Thanks guys. Both worked.