Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How do I Assign role to new user with asp.net 2.0 CreateUserWizard

I am trying to assign a role to my users when they signup. Im using the asp.net 2.0 CreateUserWizard.  It create the user, but does not assign the role.  Below is what i have for code.  Can some one show me what Im doing wrong?

Thanks for any help.

Code behind page:

protected void Page_Load(object sender, EventArgs e)
    {
 
    }
        protected void CreateUserWizard1_CreatedUser(
    object sender, EventArgs e)
    {  
         Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");
    }


html page:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
            Height="195px" Width="367px">
            <WizardSteps>
                <asp:CreateUserWizardStep runat="server" />
                <asp:CompleteWizardStep runat="server" />
            </WizardSteps>
        </asp:CreateUserWizard>
Avatar of naspinski
naspinski
Flag of United States of America image

replace:
Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");

with
Response.Write(CreateUserWizard1.UserName);

to make sure it is sending the name you thought it was sending. This will also make sure this event is firing.
Avatar of bmanmike39
bmanmike39

ASKER

I replaced the line of code.  It created the user but did not fire response redirect.
ok, so that event is never actually firing.  In your aspx, it does not look like your CreateUserWizard has this event declared?  Otherwise, that event won't get fired.

oncreateduser="CreateUserWizard1_CreatedUser"
where do i put this code?  in page load?
ASKER CERTIFIED SOLUTION
Avatar of naspinski
naspinski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank it woked!!!