Hello my fellow community goers. I am having a bit of trouble that I have been trying to figure out all day and am in need of some help. I am currently in the middle of trying to register a user for my web app using a CreateUserWizard control. This works
fine and creates a new user no problem.
The part that I am finding difficult is I have added a DropDownList inside of the CreateUserWizard control that populates the Roles I have created but when selecting a role from the DropDownList and clicking the CreateUserWizard button to save the user and
their role to the MySql database I have it hooked up to it just doesn't want to save?
Below is the code that I have been tinkering with all day and I believe I am very close.
#Region " Page Load"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
GetRoles()
End If
End Sub
#End Region
#Region " Get User Roles"
Private Sub GetRoles()
ddlUserType = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlUserType"), DropDownList)
ddlUserType.DataSource = Roles.GetAllRoles()
ddlUserType.DataBind()
If (Not Roles.IsUserInRole("Admin")) Then
ddlUserType.Items.Remove("Admin")
End If
End Sub
#End Region
#Region " Events"
Protected Sub CreateUserWizard1_CreatedUser1(sender As Object, e As EventArgs)
Roles.AddUserToRole(TryCast(sender, CreateUserWizard).UserName, ddlUserType.SelectedValue)
End Sub
#End Region
I have noticed that the role table will get updated if I add the actual name of the role instead of the DropDownList.SelectedValue so it has it be something regarding the DropDownList? Just not sure what?
morrisandy
Member
30 Points
46 Posts
Saving a Role from a DropDownList inside a CreateUserWizard to the my_asp_usersinroles table insi...
Jan 06, 2013 05:47 AM|LINK
Hello my fellow community goers. I am having a bit of trouble that I have been trying to figure out all day and am in need of some help. I am currently in the middle of trying to register a user for my web app using a CreateUserWizard control. This works fine and creates a new user no problem.
The part that I am finding difficult is I have added a DropDownList inside of the CreateUserWizard control that populates the Roles I have created but when selecting a role from the DropDownList and clicking the CreateUserWizard button to save the user and their role to the MySql database I have it hooked up to it just doesn't want to save?
Below is the code that I have been tinkering with all day and I believe I am very close.
FrontEnd
<asp:CreateUserWizard ID="CreateUserWizard1" OnCreatedUser="CreateUserWizard1_CreatedUser1" runat="server"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlUserType" AppendDataBoundItems="true" runat="server"> <asp:ListItem Text="-- Select User Type --" Value="0"></asp:ListItem> </asp:DropDownList> </ContentTemplate> </WizardSteps> </asp:CreateUserWizard>BackEnd
#Region " Page Load" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not Page.IsPostBack) Then GetRoles() End If End Sub #End Region #Region " Get User Roles" Private Sub GetRoles() ddlUserType = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlUserType"), DropDownList) ddlUserType.DataSource = Roles.GetAllRoles() ddlUserType.DataBind() If (Not Roles.IsUserInRole("Admin")) Then ddlUserType.Items.Remove("Admin") End If End Sub #End Region #Region " Events" Protected Sub CreateUserWizard1_CreatedUser1(sender As Object, e As EventArgs) Roles.AddUserToRole(TryCast(sender, CreateUserWizard).UserName, ddlUserType.SelectedValue) End Sub #End Regionmorrisandy
Member
30 Points
46 Posts
Re: Saving a Role from a DropDownList inside a CreateUserWizard to the my_asp_usersinroles table ...
Jan 06, 2013 06:17 AM|LINK
I have noticed that the role table will get updated if I add the actual name of the role instead of the DropDownList.SelectedValue so it has it be something regarding the DropDownList? Just not sure what?
morrisandy
Member
30 Points
46 Posts
Re: Saving a Role from a DropDownList inside a CreateUserWizard to the my_asp_usersinroles table ...
Jan 06, 2013 06:58 AM|LINK
I finally managed to figure it out. Adding the Init Page Event with the GetRoles() sub did the trick:
Private Sub admin_Init(sender As Object, e As EventArgs) Handles Me.Init GetRoles() End Sub