Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:LoginView ID="LoginView1" runat="server">
        <LoggedInTemplate>
            You are already Registered...
        </LoggedInTemplate>
         <AnonymousTemplate>
            <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8"
                BorderStyle="Solid" BorderWidth="1px" CancelDestinationPageUrl="~/" ContinueDestinationPageUrl="~/CustomerDetails.aspx"
                CreateUserButtonText="Sign Up" Font-Names="Verdana" Font-Size="0.8em" OnCreatedUser="CreateUserWizard1_CreatedUser" FinishDestinationPageUrl="~/CustomerDetails.aspx">
                <SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
                <SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
                <ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                    BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
                <NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                    BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
                <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
                    ForeColor="White" HorizontalAlign="Center" />
                <CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                    BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
                <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <StepStyle BorderWidth="0px" />
                <WizardSteps>
                    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
                        <ContentTemplate>
                            <table border="0" style="font-size: 100%; font-family: Verdana">
                                <tr>
                                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                        Sign Up for Your New Account</td>
                                </tr>
                                
                               <tr>
                                    <td align="right">
                                        <asp:Label ID="NameLabel" runat="server" AssociatedControlID="Name">Name:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Name" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="NameRequired" runat="server" ControlToValidate="Name"
                                            ErrorMessage="Name is required." ToolTip="Name is required." ValidationGroup="RegisterGroup1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="SurnameLabel" runat="server" AssociatedControlID="Surname">Surname:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Surname" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="SurnameRequired" runat="server" ControlToValidate="Surname"
                                            ErrorMessage="Surname is required." ToolTip="Surname is required." ValidationGroup="RegisterGroup1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Email Address:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                                            ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
                                            ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
                                            ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1" Visible="False">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question" Visible="False">Security Question:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Question" runat="server" Visible="False"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question"
                                            ErrorMessage="Security question is required." ToolTip="Security question is required."
                                            ValidationGroup="CreateUserWizard1" Visible="False">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer" Visible="False">Security Answer:</asp:Label></td>
                                    <td>
                                        <asp:TextBox ID="Answer" runat="server" Visible="False"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
                                            ErrorMessage="Security answer is required." ToolTip="Security answer is required."
                                            ValidationGroup="CreateUserWizard1" Visible="False">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2">
                                        <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                            ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                            ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" style="color: red">
                                        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                    </td>
                                </tr>
                            </table> 
                        </ContentTemplate>
                    </asp:CreateUserWizardStep>
                    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" OnActivate="CompleteWizardStep1_Activate">
                        <ContentTemplate>
                            <table border="0" style="font-size: 100%; font-family: Verdana">
                                <tr>
                                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                        Complete</td>
                                </tr>
                                <tr>
                                    <td>
                                        Your account has been successfully created.</td>
                                </tr>
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="ContinueButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC"
                                            BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                                            Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
                                    </td>
                                </tr>
                            </table>
                        </ContentTemplate>
                    </asp:CompleteWizardStep>
                </WizardSteps>
            </asp:CreateUserWizard>
        </AnonymousTemplate>
    </asp:LoginView>
</asp:Content>





C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Profile;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            // set the title of the page
        this.Title = BalloonShopConfiguration.SiteName +
            " : Register";
    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        Roles.AddUserToRole((sender as CreateUserWizard).UserName,
            "Customer");
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
        p.Name = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Name")).Text;
        p.Surname = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Surname")).Text;
        p.Save(); 
    }
    public void CompleteWizardStep1_Activate(object sender, EventArgs e)
    {
        Response.Redirect("CustomerDetails.aspx");
    }
}


in
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
I get an error that 'CreateUserWizzard1' does not exist in the current context although my method CreateUserWizard1_CreatedUser.

Please help I do not know what may cause this error.
Posted

Hi jellybeannn, hope you're fine...

At code-behind inn your program (CreateUserWizard1_CreateUser handler), you put this line of code...

Roles.AddUserToRole((sender as CreateUserWizard).UserName,"Customer");


Up to this point program is okay, because it get the element as object from sender and cast it to use as CreateUserWizard type object.

The problem starts from next statement which is something like...

ProfileCommon p = ......


I suggest to take the element you extracted from sender into a CreateUserWizard type variable... and then use this variable to refer actual element... lets see the approach...

replace your handler function with one given below:

C#
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)    
{        
      CreateUserWizard cuw = (CreateUserWizard) sender; 
      Roles.AddUserToRole(cuw.UserName,"Customer");                       
      ProfileCommon p = (ProfileCommon)ProfileCommon.Create(cuw.UserName, true);        
      p.Name = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Name")).Text;        
      p.Surname = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Surname")).Text;        
      p.Save();     
}


or you can try another approach by extracting CreateUserWizard element from containing element (not by sender)... try this code:

C#
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
      CreateUserWizard cuw = (CreateUserWizard) LoginView1.FindControl("CreateUserWizard1");
      Roles.AddUserToRole(cuw.UserName,"Customer");
      ProfileCommon p = (ProfileCommon)ProfileCommon.Create(cuw.UserName, true);
      p.Name = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Name")).Text;
      p.Surname = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Surname")).Text;
      p.Save();
}



I hope you got your answer...Good Luck!
 
Share this answer
 
v2
use event CreatingUser,not CreatingUser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900