Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:00:19+00:00 2026-06-02T15:00:19+00:00

I am using a CreateUserWizard together with a custom MembershipProvider to add a user

  • 0

I am using a CreateUserWizard together with a custom MembershipProvider to add a user to our database. Currently the user is successfully added to the database and I am using the CreatedUser event to store the additional information captured on the form. This works fine; however, I want to be able to handle any error conditions during the update.

Is there a way to redisplay the CreateUserWizard form with an error should the update of the additional details fails?

Here is the code I have in the CreatedUser event:

protected void RegisterUserWizard_CreatedUser(object sender, EventArgs e)
{
    try
    {
        // Try to update the customer table with the additional information
        using (OrderEntities entities = new OrderEntities())
        {
            // Read in all the values from the form
            TextBox custTitle = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerTitle");
            TextBox custName = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerName");
            TextBox custSurname = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerSurname");
            TextBox custAddress1 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine1");
            TextBox custAddress2 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine2");
            TextBox custAddress3 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine3");
            TextBox custCity = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCity");
            TextBox custCounty = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCounty");
            TextBox custPostcode = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerPostcode");
            DropDownList custCountry = (DropDownList)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCountry");

            Customer custInfo = entities.Customers.Where(c => c.UserName == RegisterUserWizard.UserName).FirstOrDefault();

            if (custInfo != null)
            {
                custInfo.Email = RegisterUserWizard.Email;
                custInfo.Password = RegisterUserWizard.Password;
                custInfo.Title = custTitle.Text;
                custInfo.Firstname = custName.Text;
                custInfo.Surname = custSurname.Text;
                custInfo.AddressLine1 = custAddress1.Text;
                custInfo.AddressLine2 = custAddress2.Text;
                custInfo.AddressLine3 = custAddress3.Text;
                custInfo.City = custCity.Text;
                custInfo.County = custCounty.Text;
                custInfo.Postcode = custPostcode.Text;
                custInfo.CountryID = custCountry.SelectedValue;
                custInfo.CreatedDate = DateTime.Now;

                entities.SaveChanges();

                FormsAuthentication.SetAuthCookie(RegisterUserWizard.UserName, false);

                // Redirect user back to calling page
                string continueUrl = RegisterUserWizard.ContinueDestinationPageUrl;
                if (String.IsNullOrEmpty(continueUrl))
                {
                    continueUrl = "~/";
                }
                Response.Redirect(continueUrl);

            }
            else
            {
                // Redisplay CreateUserWizard showing error message
            }
        }
    }
    catch
    {
        // Redisplay CreateUserWizard showing error message
    }
}

Many thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:00:26+00:00Added an answer on June 2, 2026 at 3:00 pm

    OK, found a workaround-hack for this one

    First, the modified CreatedUser Event handler:

    protected void RegisterUserWizard_CreatedUser(object sender, EventArgs e)
    {
        try
        {
            // Try to update the customer table with the additional information
            using (OrderEntities entities = new OrderEntities())
            {
                // Read in all the values from the form
                TextBox custTitle = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerTitle");
                TextBox custName = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerName");
                TextBox custSurname = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerSurname");
                TextBox custAddress1 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine1");
                TextBox custAddress2 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine2");
                TextBox custAddress3 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine3");
                TextBox custCity = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCity");
                TextBox custCounty = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCounty");
                TextBox custPostcode = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerPostcode");
                DropDownList custCountry = (DropDownList)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCountry");
    
                Customer custInfo = entities.Customers.Where(c => c.UserName == RegisterUserWizard.UserName).FirstOrDefault();
    
                if (custInfo != null)
                {
                    custInfo.Email = RegisterUserWizard.Email;
                    custInfo.Password = RegisterUserWizard.Password;
                    custInfo.Title = custTitle.Text;
                    custInfo.Firstname = custName.Text;
                    custInfo.Surname = custSurname.Text;
                    custInfo.AddressLine1 = custAddress1.Text;
                    custInfo.AddressLine2 = custAddress2.Text;
                    custInfo.AddressLine3 = custAddress3.Text;
                    custInfo.City = custCity.Text;
                    custInfo.County = custCounty.Text;
                    custInfo.Postcode = custPostcode.Text;
                    custInfo.CountryID = custCountry.SelectedValue;
                    custInfo.CreatedDate = DateTime.Now;
    
                    entities.SaveChanges();
    
                    FormsAuthentication.SetAuthCookie(RegisterUserWizard.UserName, false);
    
                    // Redirect user back to calling page
                    string continueUrl = RegisterUserWizard.ContinueDestinationPageUrl;
                    if (String.IsNullOrEmpty(continueUrl))
                    {
                        continueUrl = "~/";
                    }
                    Response.Redirect(continueUrl);
    
                }
                else
                {
                    // Throw an Exception so that we redisplay CreateUserWizard showing error message
                    throw new Exception("An error occurred updating account details, please try again");
                }
            }
        }
        catch (Exception ex)
        {
            // Delete the incomplete user from the membership to avoid duplicate UserName errors if the user tries again
            Membership.DeleteUser(RegisterUserWizard.UserName); 
    
            // Store the error message in the Context and transfer back to the page preserving the form
            Context.Items.Add("ErrorMessage", ex.Message);
            Server.Transfer(Request.Url.PathAndQuery, true);
        }
    }
    

    Next, I added a CustomValidator to ContentTemplate so that I can display the error message:

    <asp:CustomValidator ID="CustomValidator" runat="server" ValidationGroup="RegisterUserValidationGroup" />
    

    Finally, I added a new handler for the CreatingUser event to read the error message from the Context and display it using the CustomValidator:

    void RegisterUserWizard_CreatingUser(object sender, LoginCancelEventArgs e)
    {
        // If we have received an error message in the Context then cancel the CreatingUser and display the message
        if (Context.Items["ErrorMessage"] != null)
        {
            CustomValidator custValidator = (CustomValidator)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomValidator");
            custValidator.ErrorMessage = Context.Items["ErrorMessage"].ToString();
            custValidator.IsValid = false;
            e.Cancel = true;
        }
    }
    

    Now if an error occurs; I can display a friendly message, tidy up the MembershipUser and most importantly, the user doesn’t end up re-typing all their details again before retrying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the createuserwizard to store additional user info into a mysql database,
I am trying to handle add a custom field to a user profile using
I'm using A createuserwizard control. On the CreatedUser Event I placed this code to
I am using the CreateUserWizard to register a user. The control's built-in logic is
I am using createuserwizard to register the users for the website. When the user
I have created a user by using CreateUserWizard - control. My web.config file is
I have created a user using the built-in CreateUserWizard - control. I can now
Using Lookout app (https://play.google.com/store/apps/details?id=com.lookout), I see every time I install or upgrade app, it'll
First time using the ASP.NET CreateUserWizard control and we are aliasing the Username Textbox
using a binary search tree I need to add to a vector all int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.