Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

RoleName always empty when adding role to CreateUserWizard

$
0
0

Hi,

first, sorry if this kind of problem ever asked and solved somewhere else, I couldn't found it.

I try to add role when registering a user.

But when I'm trying to add the user to the roles I always get an error message saying that the rolename is empty.

Here is my code, mostly taken from default register.aspx.

<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false"
        OnCreatedUser="RegisterUser_CreatedUser" DisplayCancelButton="True"
        LoginCreatedUser="False"><LayoutTemplate><asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder><asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder></LayoutTemplate><WizardSteps><asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server"><ContentTemplate>
                      .....<p><asp:Label ID="UserRoleLabel" runat="server" AssociatedControlID="UserRole">Role:</asp:Label><asp:DropDownList ID="UserRole" runat="server" Width="320px"></asp:DropDownList><asp:RequiredFieldValidator ID="RoleRequired" runat="server" ControlToValidate="UserRole"
                                        CssClass="failureNotification" ErrorMessage="Role is required" ToolTip="Set the role to the user"
                                        ValidationGroup="RegisterUserValidationGrou">*</asp:RequiredFieldValidator></p>
                      .....</ContentTemplate><CustomNavigationTemplate></CustomNavigationTemplate></asp:CreateUserWizardStep></WizardSteps></asp:CreateUserWizard>


The code createduser event

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            string cUserName     = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
            string cRole = ((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserRole")).SelectedValue;

            Roles.AddUserToRole(cUserName, cRole);
        }

The problem is cRole is always empty, even I'm sure that the role in dropdown list has value.

Thanks in advance for the help.


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>