Source Error:
Line 55: MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
Line 56:
Line 57: Object UserGUID= User.ProviderUserKey; //error appeared here
Line 58:
Line 59: DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
I had a additional steps in createuserwizard, and upon completing the form, it would stored user info inside the DB. However this error occured :
Object reference not set to an instance of an object.
I had also set a breakpoint to link 55, 57, 59. And from line 57, User are null, they could not get the User from the DB.
Code behind :
protected void CreateUserWizard1_CreatedUser(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
MSCaptcha.CaptchaControl Captcha1 = (CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captcha1") as MSCaptcha.CaptchaControl);
TextBox txtCaptcha = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCaptcha");
Label Captchalbl = (Label)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captchalbl");
Response.Write(txtCaptcha.Text);
Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
if (!Captcha1.UserValidated)
{
Captchalbl.Text = "InValid";
e.Cancel = true;
}
else
{
Captchalbl.Text = "Valid";
TextBox UserNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
Object UserGUID= User.ProviderUserKey; //here is link 57.
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
}
Although this method name is “CreateUserWizard1_CreatedUser”, I can see it is for the CreatingUser event because of its signature. During this event the user has not been created yet. Use the CreatedUser event for that.