Reputation: 1841
I am trying to allow a user to select a role on createuserwizard from a dropdownlist containing all roles. I dont get errors but user always added to the "Offering Rooms" role no matter what dropdownlist item is selected.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
roleDropDownList = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")
roleDropDownList.DataSource = Roles.GetAllRoles()
roleDropDownList.DataBind()
End Sub
Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
Roles.AddUserToRole(RegisterUser.UserName, roleDropDownList.SelectedValue)
End Sub
Markup:
<asp:DropDownList ID="RoleDropDownList" runat="server">
</asp:DropDownList>
Html:
<option value="Offering Rooms">Offering Rooms</option>
<option value="Seeking Rooms">Seeking Rooms</option>
Upvotes: 0
Views: 311
Reputation: 13296
You need to add check if this is post back and not bind again:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
roleDropDownList = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")
roleDropDownList.DataSource = Roles.GetAllRoles()
roleDropDownList.DataBind()
End If
End Sub
Upvotes: 2