Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateUserWizard - add step but don't create user until all steps complete

I want to make use of the ootb ASP.NET2.0 MembershipProvider CreateUserWizard control, with a little customization to add a 2nd step.

The problem is that if my first step is type <asp:CreateUserWizardStep...> and my 2nd is <asp:WizardStep...>, the user is actually create imediately after the user clicks through from the first step and before they get to the second step.

here's the (very) basic control I'm using:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
   <WizardSteps>
      <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
      </asp:CreateUserWizardStep>
      <asp:WizardStep runat="server" Title="License Step">
      </asp:WizardStep>
      <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
      </asp:CompleteWizardStep>
   </WizardSteps>
</asp:CreateUserWizard>

Is there anyway to tell the control to wait until all steps are complete before creating the user?

like image 556
QMKevin Avatar asked Jun 14 '11 21:06

QMKevin


1 Answers

I had the same problem.

It seems that there is no other way to utilize the CreateUserWizard with the order that you want:

Step 1. User Creation 

Step 2. License Step etc.

After CreateUserWizardStep the data will always be written to the database, unless you override the CreateUserWizard classes.

If you reverse the order of the steps it should work as published by Erich Peterson in 4GuysFromRolla website, i.e. Step 1. License Step, Step 2. ... Step 3. User Creation.

UPDATE:

I've found a relevant post which might help. In short:

If you want to prevent the CreateUserWizard's CreateUser step from creating the user, you can try to handle the CreatingUser event and set its LoginCancelEventArgs.Cancel property to true.

Example code:

protected void RegisterUser_CreatingUser(object sender, LoginCancelEventArgs e) 
{
 e.Cancel = true; 
} 

Then in order to move to the next page in the wizard you need to handle NextButtonClick event:

  1. Add e.Cancel = False;
  2. Add CreateUserWizard.ActiveStepIndex = (your next wizard step index);

After that you will need to create the user manually, e.g. in FinishButtonClick event handler.

I haven't tried it yet but it should work. Hope it helps.

like image 157
Kirill Avatar answered Oct 30 '22 06:10

Kirill