- Joined
- 31 Dec 2003
- Posts
- 5,172
- Location
- Barrow-In-Furness
I'm setting up my page that will manage roles, and i'm struggling with deleting a role that contain users.
I would like a label to be set when the user tries to delete a role that is not empty, the code i'm using is:
When I also delete a roll that isn't populated, the label sets to "Role is populated", but the role gets deleted.
This doesn't work and caused the page to crash with the error "Role cannot be deleted because there are users present in it".
Anyone got any ideas?
For reference here is the code for the rest of the page:
I would like a label to be set when the user tries to delete a role that is not empty, the code i'm using is:
When I also delete a roll that isn't populated, the label sets to "Role is populated", but the role gets deleted.
Code:
If Roles.DeleteRole(DropDownList1.SelectedItem.ToString(), True) Then
Label2.Text = "Role is populated"
Else
Label2.Text = ""
Roles.DeleteRole(DropDownList1.SelectedItem.ToString())
RolesDefinedDropDownList()
This doesn't work and caused the page to crash with the error "Role cannot be deleted because there are users present in it".
Anyone got any ideas?
For reference here is the code for the rest of the page:
Code:
Partial Class Management_RoleManagement
Inherits System.Web.UI.Page
Protected Sub RolesDefinedDropDownList()
DropDownList1.DataSource = Roles.GetAllRoles
DropDownList1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
RolesDefinedDropDownList()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Roles.RoleExists(TextBox1.Text) = True Then
Label1.Text = "Role already exists"
Else
Roles.CreateRole(TextBox1.Text)
TextBox1.Text = ""
Label1.Text = ""
RolesDefinedDropDownList()
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If Roles.DeleteRole(DropDownList1.SelectedItem.ToString(), True) Then
Label2.Text = "Role is populated"
Else
Label2.Text = ""
Roles.DeleteRole(DropDownList1.SelectedItem.ToString())
RolesDefinedDropDownList()
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
BulletedList1.DataSource = Roles.GetUsersInRole(DropDownList1.SelectedItem.ToString())
BulletedList1.DataBind()
End Sub
End Class
Last edited: