I have a create user wizard control and have added some more fields for it and want to store that extra info into another table in the same DB. I have tried several tutorials and none seem to work. The one below, I get error, "Object reference not set to an instance of an object"
What I'm is doing wrong. Maybe there is something extra I need to do for the table I set up? links, etc would help. Thanks
The table name is ExtraUserInfo. The other tables are default setup for membership services....aspnet_reqsql.exe
Here is the source
<asp:SqlDataSource ID="ExtraUserInfo" runat="server" ConnectionString="LoginSQL"
InsertCommand="INSERT INTO [ExtraUserInfo] ([CompanyName]) VALUES (#CompanyName)"
ProviderName="MySqlLoginProvider">
<InsertParameters>
<asp:ControlParameter Name="CompanyName" Type="String" ControlID="CompanyName" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
c#
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Guid userFKey;
MembershipUser mu = Membership.GetUser(CreateUserWizard1.UserName);
userFKey = (Guid)mu.ProviderUserKey;
TextBox UserNameTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("CompanyName");
SqlDataSource DataSource = (SqlDataSource)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ExtraUserInfo");
object UserGUID = mu.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
Full error
Line 48: object UserGUID = mu.ProviderUserKey;
Line 49:
Line 50: DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
Line 51: DataSource.Insert();
Line 52:
Whole createuserwizard source
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table>
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="CompanyNameLabel" runat="server" AssociatedControlID="CompanyName">Company Name:</asp:Label></td>
<td>
<asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="CompanyNameValidator" runat="server" ControlToValidate="CompanyName"
ErrorMessage="Company Name is required." ToolTip="Company Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="FirstNameLabel" runat="server" AssociatedControlID="FirstName">First Name:</asp:Label></td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FirstName"
ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="LastNameLabel" runat="server" AssociatedControlID="LastName">Last Name:</asp:Label></td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="LastName"
ErrorMessage="Last Name is required." ToolTip="Last Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AddressLabel" runat="server" AssociatedControlID="Address">Address:</asp:Label></td>
<td>
<asp:TextBox ID="Address" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Address"
ErrorMessage="Address is required." ToolTip="Address is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PhoneNumberLabel" runat="server" AssociatedControlID="PhoneNumber">Phone Number:</asp:Label></td>
<td>
<asp:TextBox ID="PhoneNumber" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="PhoneNumber"
ErrorMessage="Phone Number is required." ToolTip="Phone Number is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorPhoneNumber" runat="server"
ControlToValidate="PhoneNumber" ToolTip="Please enter in a phone number (xxx-xxx-xxxx)" ErrorMessage="Please enter a valid phone number (xxx-xxx-xxxx)"
ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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>
<asp:RegularExpressionValidator ID="EmailCorrectFormat" runat="server"
ControlToValidate="Email" ToolTip="E-mail in a correct format is required." ErrorMessage=" Please enter a valid email (Ex. bob#gmail.com)"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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="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>
<asp:SqlDataSource ID="ExtraUserInfo" runat="server" ConnectionString="LoginSQL"
InsertCommand="INSERT INTO [ExtraUserInfo] ([CompanyName]) VALUES (#CompanyName)"
ProviderName="MySqlLoginProvider">
<InsertParameters>
<asp:ControlParameter Name="CompanyName" Type="String" ControlID="CompanyName" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
In code behind follow this: i got it from here{https://web.archive.org/web/20211020103243/https://www.4guysfromrolla.com/articles/070506-1.aspx}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox UserNameTextBox = (TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource = (SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
object UserGUID = User.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
Related
How to access LoginView1 control inside Multiview1, View2?
I have a some textbox and dropdownlist in loggedIn template of View 2 within Multiview, I need to get the control and bind with text from database.
I had try:
((TextBox)this.LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((TextBox)LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((TextBox)LoginView1.FindControl("custEmail")).Text = "xxxx";
return "Object reference not set to an instance of an object."
Markup Code
<asp:View ID="View2" runat="server" OnActivate="login_Click">
<asp:Label ID="tprice" runat="server" /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
<AnonymousTemplate>
Please login to continue.<br />
<asp:Login ID="Login1" runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
<fieldset>
<legend>Log in Form</legend>
<ul>
<li>
<asp:Label ID="Label2" runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label ID="Label4" runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
</ul>
<asp:Button ID="login" runat="server" CommandName="Login" OnCommand="login_Click"
Text="Log in"
CssClass="btn btn-info" />
</fieldset>
<asp:Label runat="server" ID="FailureText" class="validation-summary-errors" />
</LayoutTemplate>
</asp:Login>
or
<a id="registerLink" runat="server" href="~/Account/Register">Register</a>
to continue
</AnonymousTemplate>
<LoggedInTemplate>
<table class="custable">
<tr>
<td>
<asp:Label ID="Label5" AssociatedControlID="title" runat="server" Text="Title : " />
</td>
<td>
<asp:DropDownList ID="title" runat="server">
<asp:ListItem Value="0">Select One...</asp:ListItem>
<asp:ListItem Value="Mr">Mr</asp:ListItem>
<asp:ListItem Value="Mrs">Mrs</asp:ListItem>
<asp:ListItem Value="Miss">Miss</asp:ListItem>
<asp:ListItem Value="Ms">Ms</asp:ListItem>
<asp:ListItem Value="Doctor">Doctor</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="title" ValueToCompare="0" Operator="NotEqual"
Text="Please select the title." CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" AssociatedControlID="name" runat="server" Text="Full Name As Per IC : " />
</td>
<td>
<asp:TextBox ID="name" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="name"
CssClass="field-validation-error" Text="*Required"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" AssociatedControlID="custEmail" runat="server" Text="Email : " />
</td>
<td>
<asp:TextBox ID="custEmail" runat="server" TextMode="Email" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="custEmail"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" AssociatedControlID="email2" runat="server" Text="Confirm Email : " />
</td>
<td>
<asp:TextBox ID="email2" runat="server" TextMode="Email" />
</td>
<td>
<asp:CompareValidator ID="CompareValidator2" ControlToCompare="email2" ControlToValidate="custEmail"
runat="server"
Operator="Equal" Type="String" Text="Please enter same Email." CssClass="field-validation-error"
ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label9" AssociatedControlID="icPassport" runat="server" Text="IC / Passport : " />
</td>
<td>
<asp:TextBox ID="icPassport" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="icPassport"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label10" AssociatedControlID="mobile" runat="server" Text="Mobile : " />
</td>
<td>
<asp:TextBox ID="mobile" runat="server" placeholder="60123456789" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="mobile"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" /><br />
<asp:CompareValidator ID="CompareValidator3" runat="server" ControlToValidate="mobile"
Operator="DataTypeCheck" Type="Double" ErrorMessage="Mobile number must be integer."
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" /><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="mobile"
ErrorMessage="Mobile Number must within 10 to 18 digits." ValidationExpression="^\d{10,18}$"
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label11" AssociatedControlID="street" runat="server" Text="Street : " />
</td>
<td>
<asp:TextBox ID="street" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="street"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label12" AssociatedControlID="townstate" runat="server" Text="Town / State : " />
</td>
<td>
<asp:TextBox ID="townstate" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="townstate"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label13" AssociatedControlID="country" runat="server" Text="Country : " />
</td>
<td>
<asp:DropDownList ID="country" runat="server" />
</td>
<td>
<asp:CompareValidator ID="CompareValidator4" runat="server"
ControlToValidate="country" ValueToCompare="Select One..." Type="String" Operator="NotEqual"
Text="*" CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label14" AssociatedControlID="postalcode" runat="server" Text="Postal Code : " />
</td>
<td>
<asp:TextBox ID="postalcode" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="postalcode"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" /><br />
<asp:CompareValidator ID="CompareValidator5" runat="server" ControlToValidate="postalcode"
Type="Integer" Operator="DataTypeCheck" ErrorMessage="Postal Code must be integer."
CssClass="field-validation-error" ValidationGroup="vg1" Display="none" /><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="postalcode"
ErrorMessage="Postal Code, 5 or 9 Digits." ValidationExpression="\d{5}?(\d{4})?$"
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label15" AssociatedControlID="yearOfBirth" runat="server" Text="Year Of Birth : " />
</td>
<td>
<asp:DropDownList ID="yearOfBirth" runat="server">
<asp:ListItem Value="0">Year</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:CompareValidator ID="CompareValidator6" runat="server"
ControlToValidate="yearOfBirth" ValueToCompare="0" Operator="NotEqual"
Text="*" CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
</table>
</LoggedInTemplate>
</asp:LoginView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" Text="Next" CommandName="NextView" runat="server" />
</asp:View>
C# Code Behind
protected void login_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
if (User.Identity.IsAuthenticated)
{
string userId = (Membership.GetUser().ProviderUserKey).ToString();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand();
string selectcmd = "select Email from Memberships where userID='" + userId + "'";
string selectcmd2 = "select custEmail, title, name, icPassport, mobile, street, townstate, postalcode, townstate, yearOfBirth from custInfo where userID='" + userId + "'";
SqlDataReader dr;
cmd = new SqlCommand(selectcmd2, con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
((TextBox)this.LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((DropDownList)LoginView1.FindControl("title")).SelectedValue = dr.GetValue(2).ToString();
((TextBox)LoginView1.FindControl("name")).Text = dr.GetValue(3).ToString();
((TextBox)LoginView1.FindControl("icPassport")).Text = dr.GetValue(4).ToString();
((TextBox)LoginView1.FindControl("mobile")).Text = dr.GetValue(5).ToString();
((TextBox)LoginView1.FindControl("street")).Text = dr.GetValue(6).ToString();
((DropDownList)LoginView1.FindControl("townstate")).SelectedValue = dr.GetValue(7).ToString();
((TextBox)LoginView1.FindControl("postalcode")).Text = dr.GetValue(8).ToString().Trim();
((TextBox)LoginView1.FindControl("townstate")).Text = dr.GetValue(9).ToString();
((DropDownList)LoginView1.FindControl("yearOfBirth")).SelectedValue = dr.GetValue(10).ToString();
}
dr.Close();
con.Close();
}
else
{
dr.Close();
cmd = new SqlCommand(selectcmd, con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
(this.LoginView1.FindControl("custEmail") as TextBox).Text = dr.GetValue(0).ToString();
}
dr.Close();
con.Close();
}
}
}
Keep in mind that FindControl searches only the current level If you want to search in the branches (inside a MultiView, Panel, PlaceHolder, etc.) as well then you have to use some kind of recursive search.
First find the control in multiview control and by using MultiView.FindControl Method and then access the child controls in that found control
some sample posts
http://www.codeproject.com/Articles/13836/Find-child-controls-inside-a-MultiView-control-in
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Object reference not set to an instance of an object errors when using CreateUserWizard
The error - "Object reference not set to an instance of an object" occured when I hit the "Next' button of my CreateUserWizard controls. I had checked through my codes that I did not leave any of my variables null. but i still can't solve this errors.
This is the caused of the error:
Line 31: DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
Source Error:
Line 29: object UserGUID = User.ProviderUserKey;
Line 30:
Line 31: DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
Line 32:
Line 33: DataSource.Insert();
This is my html code file:
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
OnCreatedUser="CreateUserWizard1_CreatedUser" CreateUserButtonText="Next"
FinishCompleteButtonText="Create User" Height="330px"
Width="512px">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" >
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>Username:</td>
<td class="style2">
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName"
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td class="style2">
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td>
Email:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Email" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator16" runat="server" ControlToValidate="Email"
ErrorMessage="Email required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Question:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Question" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question"
ErrorMessage="Question is required." />
</td>
</tr>
<tr>
<td>Answer:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Answer" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer"
ErrorMessage="Answer is required." />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:WizardStep ID="CreateUserWizardStep0" runat="server" Title="User Details">
<table>
<tr>
<th>Billing Information</th>
</tr>
<tr>
<td>Name:</td>
<td class="style1">
<asp:TextBox runat="server" ID="CustName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator18" ControlToValidate="CustName"
ErrorMessage="Name is required." />
</td>
</tr>
<tr>
<td>Contact Number:</td>
<td class="style1">
<asp:TextBox runat="server" ID="CustNum" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator19" ControlToValidate="CustNum"
ErrorMessage="Contact num is required." />
</td>
</tr>
<tr>
<td>Role:</td>
<td class="style1">
<asp:DropDownList ID="CustRole" runat="server" AutoPostBack="True" Height="16px"
Width="123px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Bride</asp:ListItem>
<asp:ListItem>Groom</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator20" ControlToValidate="CustRole"
ErrorMessage="Role is required." />
</td>
</tr>
<tr>
<td>
Status:</td>
<td class="style1">
<asp:DropDownList ID="CustStatus" runat="server" AutoPostBack="True"
Height="17px" Width="121px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Status A</asp:ListItem>
<asp:ListItem>Status B</asp:ListItem>
<asp:ListItem>Status C</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="CustStatus"
ErrorMessage="Status is required."/>
</td>
</tr>
<tr>
<td>
</td>
<td class="style1">
</td>
</tr>
<tr>
<td>
Partner's Name:</td>
<td class="style1">
<asp:TextBox runat="server" ID="PName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="PName"
ErrorMessage="PName is required." />
</td>
</tr>
<tr>
<td>
Partner Email:</td>
<td class="style1">
<asp:TextBox runat="server" ID="PEmail" />
</td>
</tr>
<tr>
<td>
PRole:
</td>
<td class="style1">
<asp:DropDownList ID="PRole" runat="server" AutoPostBack="True" Height="16px"
Width="123px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Bride</asp:ListItem>
<asp:ListItem>Groom</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" ControlToValidate="PRole"
ErrorMessage="PRole is required." />
</td>
</tr>
<tr>
<td>
Wed Date:
</td>
<td class="style1">
<cc1:DatePicker ID="WedDate" runat="server" CalendarDate=""
TextCssClass="" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server" ControlToValidate="WedDate"
ErrorMessage="Wedding date required"/>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>
<table>
<tr>
<td align="center" colspan="2">
Complete</td>
</tr>
<tr>
<td>
Your account has been successfully created.</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False"
CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
InsertCommand="INSERT INTO [UserDetails] ([UserId], [CustName], [CustNum], [CustRole], [CustStatus], [PName], [PEmail], [PRole], [WedDate]) VALUES (#UserId, #CustName, #CustNum, #CustRole, #CustStatus, #PName, #PEmail, #PRole, #WedDate)"
ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
<InsertParameters>
<asp:ControlParameter Name="CustName" Type="String" ControlID="CustName" PropertyName="Text" />
<asp:ControlParameter Name="CustNum" Type="String" ControlID="CustNum" PropertyName="Text" />
<asp:ControlParameter Name="CustRole" Type="String" ControlID="CustRole" PropertyName="Text" />
<asp:ControlParameter Name="CustStatus" Type="String" ControlID="CustStatus" PropertyName="Text" />
<asp:ControlParameter Name="PName" Type="String" ControlID="PName" PropertyName="Text" />
<asp:ControlParameter Name="PEmail" Type="String" ControlID="PEmail" PropertyName="Text" />
<asp:ControlParameter Name="PRole" Type="String" ControlID="PRole" PropertyName="Text" />
<asp:ControlParameter Name="WedDate" Type="String" ControlID="WedDate" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
<br />
</div>
This is the code behind:
using System;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox UserName=
(TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserName.Text);
object UserGUID = User.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString()); //the error lies at here
DataSource.Insert();
}
}
The InsertExtraInfo is actually inside CompleteWizardStep1. Try this:
SqlDataSource DataSource =
(SqlDataSource)CompleteWizardSetp1.ContentTemplateContainer
.FindControl("InsertExtraInfo");
But I believe you can use the outermost container CreateUserWizard1 so you don't have to worry about which step it's in.
CreateUserWizard1.FindControl("InsertExtraInfo");
you dont need to place SqlDataSource control inside wizardcontrol. move it out. and you dont need to find it. just access it by its ID.
The error - "Object reference not set to an instance of an object" occured when I hit the "Next' button of my CreateUserWizard controls. I had checked through my codes that I did not leave any of my variables null. but i still can't solve this errors.
Source Error:
Line 29: object UserGUID = User.ProviderUserKey;
Line 30:
Line 31: DataSource.InsertParameters.Add("UserId", UserGUID.ToString()); //this is the line that caused the error
Line 32:
Line 33: DataSource.Insert();
This is my html code file:
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
OnCreatedUser="CreateUserWizard1_CreatedUser" CreateUserButtonText="Next"
FinishCompleteButtonText="Create User" Height="330px"
Width="512px">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" >
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>Username:</td>
<td class="style2">
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName"
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td class="style2">
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td>
Email:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Email" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator16" runat="server" ControlToValidate="Email"
ErrorMessage="Email required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Question:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Question" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question"
ErrorMessage="Question is required." />
</td>
</tr>
<tr>
<td>Answer:</td>
<td class="style2">
<asp:TextBox runat="server" ID="Answer" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer"
ErrorMessage="Answer is required." />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:WizardStep ID="CreateUserWizardStep0" runat="server" Title="User Details">
<table>
<tr>
<th>Billing Information</th>
</tr>
<tr>
<td>Name:</td>
<td class="style1">
<asp:TextBox runat="server" ID="CustName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator18" ControlToValidate="CustName"
ErrorMessage="Name is required." />
</td>
</tr>
<tr>
<td>Contact Number:</td>
<td class="style1">
<asp:TextBox runat="server" ID="CustNum" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator19" ControlToValidate="CustNum"
ErrorMessage="Contact num is required." />
</td>
</tr>
<tr>
<td>Role:</td>
<td class="style1">
<asp:DropDownList ID="CustRole" runat="server" AutoPostBack="True" Height="16px"
Width="123px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Bride</asp:ListItem>
<asp:ListItem>Groom</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator20" ControlToValidate="CustRole"
ErrorMessage="Role is required." />
</td>
</tr>
<tr>
<td>
Status:</td>
<td class="style1">
<asp:DropDownList ID="CustStatus" runat="server" AutoPostBack="True"
Height="17px" Width="121px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Status A</asp:ListItem>
<asp:ListItem>Status B</asp:ListItem>
<asp:ListItem>Status C</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="CustStatus"
ErrorMessage="Status is required."/>
</td>
</tr>
<tr>
<td>
</td>
<td class="style1">
</td>
</tr>
<tr>
<td>
Partner's Name:</td>
<td class="style1">
<asp:TextBox runat="server" ID="PName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="PName"
ErrorMessage="PName is required." />
</td>
</tr>
<tr>
<td>
Partner Email:</td>
<td class="style1">
<asp:TextBox runat="server" ID="PEmail" />
</td>
</tr>
<tr>
<td>
PRole:
</td>
<td class="style1">
<asp:DropDownList ID="PRole" runat="server" AutoPostBack="True" Height="16px"
Width="123px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Bride</asp:ListItem>
<asp:ListItem>Groom</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" ControlToValidate="PRole"
ErrorMessage="PRole is required." />
</td>
</tr>
<tr>
<td>
Wed Date:
</td>
<td class="style1">
<cc1:DatePicker ID="WedDate" runat="server" CalendarDate=""
TextCssClass="" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server" ControlToValidate="WedDate"
ErrorMessage="Wedding date required"/>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>
<table>
<tr>
<td align="center" colspan="2">
Complete</td>
</tr>
<tr>
<td>
Your account has been successfully created.</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False"
CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
InsertCommand="INSERT INTO [UserDetails] ([UserId], [CustName], [CustNum], [CustRole], [CustStatus], [PName], [PEmail], [PRole], [WedDate]) VALUES (#UserId, #CustName, #CustNum, #CustRole, #CustStatus, #PName, #PEmail, #PRole, #WedDate)"
ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
<InsertParameters>
<asp:ControlParameter Name="CustName" Type="String" ControlID="CustName" PropertyName="Text" />
<asp:ControlParameter Name="CustNum" Type="String" ControlID="CustNum" PropertyName="Text" />
<asp:ControlParameter Name="CustRole" Type="String" ControlID="CustRole" PropertyName="Text" />
<asp:ControlParameter Name="CustStatus" Type="String" ControlID="CustStatus" PropertyName="Text" />
<asp:ControlParameter Name="PName" Type="String" ControlID="PName" PropertyName="Text" />
<asp:ControlParameter Name="PEmail" Type="String" ControlID="PEmail" PropertyName="Text" />
<asp:ControlParameter Name="PRole" Type="String" ControlID="PRole" PropertyName="Text" />
<asp:ControlParameter Name="WedDate" Type="String" ControlID="WedDate" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
<br />
</div>
This is the code behind:
using System;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox UserName=
(TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserName.Text);
object UserGUID = User.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString()); //the error lies at here
DataSource.Insert();
}
}
I had checked through my codes that I did not leave any of my
variables null. but i still can't solve this errors.
You have not checked all your variables, otherwise this error would not be occurring.
Have you checked your DataSource to ensure the SqlDataSource is being found? The InsertParameters property of the DataSource to ensure that it is not null? The UserGUID to ensure that it is not null?
I am adding some regex with the register user steps, they are working because the '*' is being displayed but the Wizard will still let me create an account with errors of regex.
I tried to redo the wizard
Changing some features but nothing
.
Page Source
<asp:CreateUserWizard ID="RegisterUser" runat="server" CssClass="gridviewUsers"
oncreateduser="RegisterUser_CreatedUser1">
<WizardSteps>
<asp:CreateUserWizardStep runat="server">
<ContentTemplate>
<table>
<tr>
<td align="center" colspan="2">
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"
ToolTip="The Username that you will need to login later eg "john123""></asp:TextBox>
<asp:RequiredFieldValidator ID="rv1_1" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ForeColor="Red" ToolTip="User Name is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rv1_2" runat="server"
ControlToValidate="UserName" ErrorMessage="Not a valid Username"
ForeColor="Red" ValidationExpression="^[a-z0-9_-]{3,15}$"
ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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"
ToolTip="The password for the selected username eg"123456""></asp:TextBox>
<asp:RequiredFieldValidator ID="rv2_1" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ForeColor="Red" ToolTip="Password is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rv2_2" runat="server"
ControlToValidate="Password"
ErrorMessage="Invalid Password Please enter a valid password rg"pass12""
ForeColor="Red" ValidationExpression="^[A-Za-z0-9]+$"
ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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"
ToolTip="Must enter the same password as above to confirm password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rv3_1" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." ForeColor="Red"
ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rv3_2" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Invalid Password Please enter a valid password rg"pass12""
ForeColor="Red" ValidationExpression="^[A-Za-z0-9]+$"
ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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"
ToolTip="The email on which we will use to contact you!"></asp:TextBox>
<asp:RequiredFieldValidator ID="rv4_1" runat="server" ControlToValidate="Email"
ErrorMessage="E-mail is required." ForeColor="Red"
ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rv4_2" runat="server"
ControlToValidate="Email" ErrorMessage="Email invalid format" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="CreateUserWizard1">*</asp:RegularExpressionValidator>
</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."
ForeColor="Red" 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>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
Aspx File
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
if (CheckUsername() != true)
{
Roles.AddUserToRole(RegisterUser.UserName, "Pre-Member");
FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);
string continueUrl = RegisterUser.ContinueDestinationPageUrl;
if (String.IsNullOrEmpty(continueUrl))
{
continueUrl = "~/Account/InsertingUserDetails.aspx";
}
Response.Redirect(continueUrl);
}
else
{
RegisterUser.UserNameRequiredErrorMessage = "User already taken";
}
}
Assuming your Create Use wizard looks like this
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser"
DisableCreatedUser="true" EmailRegularExpression="^((?:(?:(?:\w[\.\-\+]?)*)\w)+)\#((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.(\w{2,4})$"
Font-Size="Small">
<CreateUserButtonStyle CssClass="button" />
<ErrorMessageStyle Font-Size="Small" />
<TextBoxStyle CssClass="textbox txtsingleline" />
<ValidatorTextStyle Font-Size="Small" />
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
You can access the validators as follows:
(RequiredFieldValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("UserNameRequired")
(RequiredFieldValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("PasswordRequired")
(RequiredFieldValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("ConfirmPasswordRequired")
(RequiredFieldValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("EmailRequired")
(CompareValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("PasswordCompare")
(RegularExpressionValidator)((CreateUserWizardStep)CreateUserWizard1.FindControl("CreateUserWizardStep1")).ContentTemplateContainer.FindControl("EmailRegExp")
Hope this helps
Thank You :)
Use the correct ID for ValidationGroup.
Should be "RegisterUser" instead of "CreateUserWizard1"
how to auto login the user after he created an account
using asp.net 3.5, and from authentication
here is the code:
<asp:CreateUserWizard ID="mainSignUp" runat="server"
CreateUserButtonText="SignUp" FinishDestinationPageUrl="copyPastPage.aspx"
ContinueDestinationPageUrl="~/copyPastPage.aspx"
OnCreatedUser="redirect" LoginCreatedUser="true">
<CreateUserButtonStyle CssClass="signUpButton" />
<TextBoxStyle BorderStyle="None" Height="35px"
Width="200px" />
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" >
<ContentTemplate>
<table>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server" BorderStyle="None" BorderWidth="1px"
CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="mainSignUp">*</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" BorderStyle="None" BorderWidth="1px"
CssClass="signUpTextBox" Height="39px" TextMode="Password" Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="mainSignUp">*</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" BorderStyle="None"
BorderWidth="1px" CssClass="signUpTextBox" Height="39px" TextMode="Password"
Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="mainSignUp">*</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" BorderStyle="None" BorderWidth="1px"
CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="mainSignUp">*</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" BorderStyle="None" BorderWidth="1px"
CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"
ControlToValidate="Question" ErrorMessage="Security question is required."
ToolTip="Security question is required." ValidationGroup="mainSignUp">*</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" BorderStyle="None" BorderWidth="1px"
CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Security answer is required."
ToolTip="Security answer is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator>
</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="mainSignUp"></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" />
</WizardSteps>
</asp:CreateUserWizard>
and the code behind :
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void redirect(object sender, EventArgs e)
{
FormsAuthentication.SetAuthCookie(USER_NAME, true);
Response.Redirect("copyPastPage.aspx");
}
}
thanks in advance
FormsAuthentication.RedirectFromLoginPage(mainSignUp.UserName, true);
Put the above line inside the redirect method and remove those two lines and let us know if that helps
After a successfull Signup, just use this line:
FormsAuthentication.SetAuthCookie(USER_NAME, true);
the true at the end means (from official documentation):
true to create a persistent cookie (one that is saved across browser sessions); otherwise, false.
If you are using CreateUserWizard control for user registration, you may set a property LoginCreatedUser to true to automatically login a user after registration is complete.