views:

470

answers:

2

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

}
A: 
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
    CreateUserWizard1.MoveTo(CompleteWizardStep1);
}
Sky Sanders
@Sky Sanders - Calling the `MoveTo` did not solve the problem.
Michael Kniskern
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
@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
@Greg, good catch. @Michael? cast a local variable? just set e.Cancel=true; and the call MoveTo. That should work just fine.
Sky Sanders
@Sky Sanders - 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
A: 

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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
@Greg - I can not watch the video because it is blocked by my WebSense at work. I will watch it when I get home.
Michael Kniskern
@Greg - I am using a web site project model instead of a web application project model. This should not make a difference.
Michael Kniskern
A developer behind WebSense is a crime. :(
Greg
@Greg - It is a crime against humanity.
Michael Kniskern