Adding roles to the 'CreateUserWizard'

Hi (I'm pretty new to this),

Is it possible to add roles to the 'CreateUserWizard' tool so that you tick boxes (or view roles in a drop down menu) and once one or more have been chosen, this information is added to the configuration automatically?

I have the following code:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="260px" Width="568px"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <table border="0" style="font-size: 100%; width: 568px; font-family: Verdana; height: 260px"> <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Create a New Account</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</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">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label></td> <td> <asp:TextBox ID="Question" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label></td> <td> <asp:TextBox ID="Answer" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</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"> <ContentTemplate> <table border="0" style="font-size: 100%; width: 568px; font-family: Verdana; height: 260px"> <tr> <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d"> Complete</td> </tr> <tr> <td style="text-align: left"> &nbsp; Your account has been successfully created</td> </tr> <tr> <td align="right" colspan="2" style="text-align: right"> <asp:Button ID="ContinueButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue" Font-Names="Verdana" ForeColor="#284775" PostBackUrl="~/Default.aspx" Text="Continue" ValidationGroup="CreateUserWizard1" Width="105px" /> &nbsp; &nbsp; &nbsp;</td> </tr> </table> </ContentTemplate> </asp:CompleteWizardStep> </WizardSteps> <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" /> </asp:CreateUserWizard>


-------------Problems Reply------------

Briefly, what you need to do is to add the roles dropdown/checklist control somewhere in the <asp:CreateUserWizardStep><ContentTemplate> section.

Since the control is in a Template, you need to use the following code to find the control in the code behind:

roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl( "RoleDropDownList" );

You'd bind it like you normally would bind a control in the Page_Init.

To add the user to the role, use the CreatedUser event of the CreateUserWizard control.

protected void CreateUserWizard1_CreatedUser( object sender, EventArgs e )
Roles.AddUserToRole( CreateUserWizard1.UserName, roleDropDownList.SelectedValue );

if you want to assign the role to the user you just created you can use this :

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

Add the dropdownlist under the last textbox of the CreateUserWizard as the following code shows. ASP:

<%---------existing items------------%>
<td align="right">
<asp:Label runat="server" AssociatedControlID="Answer" ID="AnswerLabel">Security Answer:</asp:Label></td>
<asp:TextBox runat="server" ID="Answer"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="Answer" ErrorMessage="Security answer is required." ValidationGroup="CreateUserWizard1" ToolTip="Security answer is required." ID="AnswerRequired">*</asp:RequiredFieldValidator>

<%---------role Dropdownlist to be inserted here------------%>
<tr><td align="right"><asp:Label runat="server" ID="RoleLabel">Role</asp:Label></td>
<asp:DropDownList ID="RoleDropDownList" runat="server"></asp:DropDownList></td>


Also you have to add in behind code the following:

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).DataSource = Roles.GetAllRoles();
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).DataBind( );
int rolecounter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).Items.Count;
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).Items[rolecounter - rolecounter].Selected = true;
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList");
Roles.AddUserToRole(CreateUserWizard1.UserName, roleDropDownList.SelectedValue);

This is working for me.Check it

see for more there

Category:c# Views:0 Time:2009-11-05

Related post

  • createuserwizard adding roles to users 2010-09-22

    Hi I have a createuserwizard controls and I would like assign ROLES when creating a user. Any idea how to do it? Thanks Here my code C# <asp:CreateUserWizard ID="uxCreateUserWizardInput" runat="server" LoginCreatedUser="False"> <WizardSteps

  • Adding columns to the CreateUserWizard control using FBA 2009-01-15

    I'm wanting to create a user account creation section for unregistered users on our internet site. I want to ask the same questions as the CreateUserWizard control but have a few changes. I want the question to come from a question lookup table in SQ

  • Adding Role to User Created in Web.config 2008-12-02

    I have a few users setup in the web.config of an site to handle authentication. Without getting into details I'm not using the full membership/role provider and would rather not have to implement it at the moment do to time constraints. Howev

  • Adding roles from a DB Table 2010-06-17

    Can anyone expalin me how to dynamically ger the Role from a DB table instead of hard coding it in the code. ClaimsIdentity outputIdentity = new ClaimsIdentity(); outputIdentity.Claims.Add(new Claim(System.IdentityModel.Claims.ClaimTypes.Name, princi

  • adding more fields to CreateUserWizard 2010-11-18

    is there an easy way to add more fileds to the CreateUserWizard control? I'd like to add 5 more fields to the existing fields. --------------Solutions------------- Add new step for your wizard and put into additional fields. To store new fields use P

  • Standard Users adding roles Server 2008 R2 2013-10-02

    We are putting together a training system for Server2k8 R2. We wish students to be able to log on as standard users but still be able to launch Server Manager then add the Hyper-V role and virtual servers to practice on. Anyone know the way to allow

  • Using Devise with Rails 3. Adding multiple roles? 2010-10-05

    We are using the devise gem for authentication in a Rails 3 application. We have multiple roles and from the devise stand-point, the roles will differ in terms of confirmation, activation and remember me functionality. The devise documentation has ex

  • Role-management provider using web.config? 2010-01-14

    I'm building a tiny web application with a simple user autentication scheme. I register the users in web.config, like this: <authentication mode="Forms"> <forms loginUrl="~/login.aspx" defaultUrl="default.aspx" ...> <credentials passwo

  • How can I grant a specific role In Ubercart? 2010-08-20

    I'm trying to grant a specific role to users that order an amount equal or greater than 100.00 €: Conditional Actions is going really near the achievement, but I'm failing on the action (PHP required). How can I grant a role using a PHP action in Ube

  • How to assign role with PHP in Drupal? 2010-08-20

    I need to assign a kind of "premium status" to members that purchase an amount equal or greater than 100 € via PHP. Conditional Actions are already set up (user = anonymous/authenticated AND total amount = equal/greater than 100 AND user =! premium)

  • liferay enable organization or community by role 2011-03-31

    I am working on a new liferay implementation. I have all of my users in an external system, and have used the external env. to authenticate through my own authentication system. I also store roles in this same system. I have been able to successfully

  • Restricting access to AD roles in an ASP.NET application 2011-05-13

    I'm fairly new to development, and am wondering how to continue with a certain problem. I have access to an existing website that uses a single web page to display multiple different reports (the type of report to be displayed determined by a

  • Rails 3: role_mask won't save - WARNING: Can't mass-assign protected attributes: roles 2011-06-28

    I'm using the code from Railscasts 189 to implement roles with Devise so I can use Cancan. However the roles are not being saved to the role_mask field. Relevant code from my user model: attr_accessible :email, :password, :password_confirmation, :rem

  • How to update role definition of a group in sharepoint 2010 programmatically? 2011-10-20

    I have created a SharePoint group programmatically with read and contribute roles. Now I am trying to update the roles of that group with other role definitions. Like full control etc. But I can't remove the existing roles from the SharePoint group.

  • Problem with Login control of ASP.NET 2008-09-15

    I set up a website to use SqlMembershipProvider as written on this page. I followed every step. I have the database, I modified the Web.config to use this provider, with the correct connection string, and the authentication mode is set to Forms. Crea

  • How to I add more custom fields using custom membership in mvc? 2012-01-06

    I have overridden the membership methods to create a custom membership. In the account model I've overridden the method CreateUser: public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, str

  • Where do I put 'helper' methods? 2009-03-02

    In my Ruby on Rails app, I've got: class AdminController < ApplicationController def create if and params[:role_data] parse_role_data(params[:role_data]) end end end and also module AdminHelper def parse_role_data(roledata) ... end e

  • Finding forums based on a user's permissions 2009-03-27

    I'm implementing a forum system called rBoard. Code is viewable at I've reached an impasse with the permissions code that I've been trying to implement and I've decided to turn to the all-knowing, ever-caring Stack Ove

  • PHP Secure Login - Client-side options? 2009-07-23

    Ok now I am confused. I have been getting advice from SO users on libraries to use with codeigniter for authentication. I have explored dx_auth and simpleloginsecure (I think I will use the latter due to its supposed secure hashing and small footprin

Copyright (C), All Rights Reserved.

processed in 0.076 (s). 11 q(s)