Saturday, July 7, 2012

Adding roles to the 'CreateUserWizard'


Add this to create user table
<tr>
<td align="right">
 <asp:Label ID="RolesLabel" runat="server" Text="Roles" AssociatedControlID="DropDownListRoles"></asp:Label>
 </td>
 <td>
 <asp:DropDownList ID="DropDownListRoles" runat="server">
 </asp:DropDownList>
 </td>
 </tr>

And then this to code
protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListRoles");
        roleDropDownList.DataSource = Roles.GetAllRoles();
        roleDropDownList.DataBind();
    }
 
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListRoles");
        Roles.AddUserToRole(CreateUserWizard1.UserName, roleDropDownList.SelectedValue);
    }

No comments:

Post a Comment