Display roles : Roles « Login Security « ASP.Net






Display roles


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Roles_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ListBox ID="lstRoles" runat="server" AutoPostBack="True"></asp:ListBox>
        <asp:ListBox ID="lstUsers" runat="server"></asp:ListBox><br />
        New Role<br />
        <asp:TextBox ID="txtRole" runat="server"></asp:TextBox>
        <asp:Button ID="btnCreateRole" runat="server" Text="Create Role" /><br />
    </form>
</body>
</html>

File: Default.aspx.vb

Partial Class Roles_aspx
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load
        If Not IsPostBack Then
            Dim allRoles() As String
            allRoles = Roles.GetAllRoles()
            lstRoles.Items.Clear()
            For i As Integer = 0 To allRoles.Length - 1
                lstRoles.Items.Add(allRoles(i).ToString)
            Next
        End If
        lstUsers.Items.Clear()
        If lstRoles.SelectedItem IsNot Nothing Then
            Dim allUsersInRole() As String = _
               Roles.GetUsersInRole(lstRoles.SelectedItem.ToString)
            For i As Integer = 0 To allUsersInRole.Length - 1
                lstUsers.Items.Add(allUsersInRole(i).ToString)
            Next
        End If
    End Sub

    Protected Sub btnCreateRole_Click(ByVal sender As Object, _
                                      ByVal e As System.EventArgs) _
                                      Handles btnCreateRole.Click
        Roles.CreateRole(txtRole.Text)
        lstRoles.Items.Add(txtRole.Text)
    End Sub
End Class

 








Related examples in the same category