1

How do I programmatically switch to the asp:CompleteWizardStep step in the OnCreatingUser event in the asp:CreateUserWizard control?

ASP.NET web form

<asp:CreateUserWizard ID="MyCreateUserWizard" runat="server" OnCreatingUser="MyCreateUserWizard_CreatingUser">
    <WizardSteps>
        <asp:CreateUserWizardStep ID="CreateUserStep1" runat="server">
            <!-- code here -->
        </asp:CreateUserWizardStep>
        <asp:CompleteWizardStep ID="CompleteWizardStep" runat="server">
            <!-- code here -->
        </asp:CompleteWizardStep>
    </WizardSteps>
</asp:CreatedWizardStep>

Code behind

protected void MyCreateUserWizard_CreatingUser(object sender, EventArgs e)
{
    //retrieve username, password and email

    Membership.CreateUser(username, password, email);

    //would like to display the CompleteWizardStpe here

}
Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
  • What does it do instead, and why are you manually creating a user instead of allowing the control to do it for you? – Greg Mar 01 '10 at 22:48
  • @Greg - It goes to the `asp:CreateUserWizardStep` view with the usename and e-mail control filled in with the input from the user. It does not show the `asp:CompleteWizardStep` view at all. Even if I do not programmatically call the `Membership.CreateUser` method. – Michael Kniskern Mar 01 '10 at 23:18
  • @Greg - I remove the `OnCreatingUser` event and it works just fine. – Michael Kniskern Mar 01 '10 at 23:52

2 Answers2

0
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
    CreateUserWizard1.MoveTo(CompleteWizardStep1);
}
Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
Sky Sanders
  • 36,396
  • 8
  • 69
  • 90
  • @Sky Sanders - Calling the `MoveTo` did not solve the problem. – Michael Kniskern Mar 01 '10 at 21:04
  • if you want to completely bypass the built-in functionality of the control, set `e.Cancel = true;` and then MoveTo. The control will no longer create a user or email them. – Greg Mar 01 '10 at 22:52
  • @Greg - Didn't not work. I cast a local variable to a `LoginCancelEventArgs` object using the `e` object and it did not display the asp:CompleteWizardStep control. – Michael Kniskern Mar 01 '10 at 23:25
  • @Greg, good catch. @Michael? cast a local variable? just set e.Cancel=true; and the call MoveTo. That should work just fine. – Sky Sanders Mar 01 '10 at 23:29
  • I was still using the original method signature from my code example with the `EventsArgs` input parameters. I changed the signature to your example and it still do not work. – Michael Kniskern Mar 01 '10 at 23:40
0

I just recreated your solution in VS2008 / .net 3.5 using the empty OnCreatingUser event handler and it "works on my computer". So, what's different that could be causing this problem?

aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default"
    Trace="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatingUser="CreateUserWizard1_CreatingUser">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
            </asp:CompleteWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>
    </form>
</body>
</html>

Code-behind:

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void CreateUserWizard1_CreatingUser(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
        {
        }
    }
}

web.config:

<authentication mode="Forms" />

Video of it working: http://www.screentoaster.com/watch/stWEJSR0ZIR19YRVleWV9QXlJX

Greg
  • 16,540
  • 9
  • 51
  • 97