I have created a create login and registration page using the CreateUserWizard using VB.NET 3.5. I am new at creating membership, and the articles I've read people are having luck with it working. I'm trying what they post as the answer and it's not working for me. So maybe someone out there can tell me what I'm doing wrong. At this point, I'm just trying to get the First name and last name to display.
So it is blowing up on:
Response.Write(txtFN.Text & " " & txtLN.Text)
I just want to do a response.write to get the values out so I can make sure they are coming out so I can add them to my stored procedure code to add it to the database. Seems like this process should be easier than this. Thanks for your help!
Here's the HMTL:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
OnNextButtonClick="CreateUserWizard1_NextButtonClick"
OnCreatedUser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/ProviderRegistration.aspx">
<WizardSteps>
<asp:WizardStep ID="CreateUserWizardStep0" runat="server">
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" style="font-weight: bold; color: white; background-color: #5d7b9d">
Select an Account Name</td>
</tr>
<tr>
<td>
<asp:Label ID="AccountNameLabel" runat="server" AssociatedControlID="SearchAccount" >
Account Name:</asp:Label>
<asp:TextBox ID="SearchAccount" runat="server"></asp:TextBox><br />
<asp:Label ID="SearchAccountMessage" runat="server" ForeColor="red" />
</td>
</tr>
</table>
</asp:WizardStep>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana">
<tr>
<td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">
User Name:</asp:Label></td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">
Password:</asp:Label></td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">
Confirm Password:</asp:Label></td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">
E-mail:</asp:Label></td>
<td>
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">
Security Question:</asp:Label></td>
<td>
<asp:TextBox ID="Question" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question"
ErrorMessage="Security question is required." ToolTip="Security question is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">
Security Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
ErrorMessage="Security answer is required." ToolTip="Security answer is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right"><b>First Name</b></td>
<td>
<asp:TextBox ID="txtFN" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right"><b>Last Name</b></td>
<td>
<asp:TextBox ID="txtLN" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right"> </td>
<td> </td>
</tr>
<tr>
<td align="right"> </td>
<td> </td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>
<table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
<tr>
<td align="center" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
Complete</td>
</tr>
<tr>
<td>
Your account has been successfully created.<br />
<br />
<asp:Label ID="SubscribeLabel" runat="server" Text="You have elected to receive our monthly newsletter."></asp:Label><br />
<br />
<asp:Label ID="ShareInfoLabel" runat="server" Text="You have elected to share your information with partner sites."></asp:Label></td>
</tr>
<tr>
<td align="right">
<asp:Button ID="ContinueButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
<NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" HorizontalAlign="Center" />
<CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
<StepStyle BorderWidth="0px" />
</asp:CreateUserWizard>
Here's the code:
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
Dim user As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
Membership.UpdateUser(user)
Dim txtLN As TextBox = CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("txtLN"), TextBox)
Dim txtFN As TextBox = CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("txtFN"), TextBox)
Session("ProviderUN") = user.UserName
Session("ProviderEmail") = user.Email
lblMessage.Text = user.Email & ", " & user.UserName
Dim userGUID As Object = user.ProviderUserKey
Response.Write(userGUID)
Response.Write(txtFN.Text & " " & txtLN.Text)
End Sub
Private Function UserExists(ByVal username As String) As Boolean
If Membership.GetUser(username) IsNot Nothing Then Return True
Return False
End Function
Protected Sub CreateUserWizard1_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
If e.CurrentStepIndex = 0 Then
If SearchAccount.Text.Trim() = "" OrElse UserExists(SearchAccount.Text) Then
SearchAccountMessage.Text = "That account already exists. Please select an different account name."
e.Cancel = True
Else
Dim userName As TextBox = _
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)
userName.Text = SearchAccount.Text
SearchAccountMessage.Text = ""
e.Cancel = False
End If
End If
End Sub
Protected Sub CreateUserWizard1_FinishButtonClick(sender As Object, e As WizardNavigationEventArgs) Handles CreateUserWizard1.FinishButtonClick
Dim u As MembershipUser
u = Membership.GetUser(User.Identity.Name)
lblMessage.Text = u.Email & ", " & u.UserName
' Response.Write(u.ProviderUserKey)
Dim txtFN As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFN"), TextBox)
Dim txtLN As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtLN"), TextBox)
objConnection.Open()
Try
Dim strAddUID As String = "spSOCATAddUID"
Dim objComm As New SqlClient.SqlCommand(strAddUID, objConnection)
objComm.CommandType = CommandType.StoredProcedure
Dim objID As New SqlClient.SqlParameter("@UserID", SqlDbType.UniqueIdentifier)
objID.Value = u.ProviderUserKey
objComm.Parameters.Add(objID)
Dim objUN As New SqlClient.SqlParameter("@UserName", SqlDbType.VarChar, 15)
objUN.Value = u.UserName
objComm.Parameters.Add(objUN)
Dim objProviderFN As New SqlClient.SqlParameter("@Fname", SqlDbType.VarChar, 50)
objProviderFN.Value = txtFN.Text
objComm.Parameters.Add(objProviderFN)
Dim objProviderLN As New SqlClient.SqlParameter("@Lname", SqlDbType.VarChar, 50)
objProviderLN.Value = txtLN.Text
objComm.Parameters.Add(objProviderLN)
Dim objEmail As New SqlClient.SqlParameter("@Email", SqlDbType.VarChar, 50)
objUN.Value = u.Email
objComm.Parameters.Add(objUN)
Catch ex As Exception
lblMessage.Text = ex.Message & "Error. Could not add provider information."
End Try
lblMessage.Text = "Provider Info entered."
objConnection.Close()
End Sub