AuthorizeAttribute for a RadComboBox

3 posts, 1 answers
  1. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 01 Nov 2012 Link to this post

    Heey Guys 

    Is there an example of how to show a Combo Box item, say "Admin" only when a user acting in the role of administrator is currently logged in?

    Thanks for help and fast answer ! `^
  2. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 06 Nov 2012 Link to this post

    Hi Nikola,

    You can populate the RadComboBox with all Roles in this way:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true"
        OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
    </telerik:RadComboBox>

    protected void Page_Load(object sender, EventArgs e)
    {
        string[] usersInRole = Roles.GetAllRoles();
        RadComboBox1.DataSource = usersInRole;
        RadComboBox1.DataBind();
    }

    Then at SelectedIndexChanged you can check whether the currently logged user is in the Role that has been selected in the combo:
    protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
         
        if (Roles.IsUserInRole(RadComboBox1.SelectedValue))
        {
            // perform some actions here...
        }
     
    }



    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 06 Nov 2012 Link to this post

    Heey

    found it by my self but still thanks . Had the  same solution as you '^^

     

Back to Top