Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:01:14+00:00 2026-05-27T20:01:14+00:00

Currently i m working on a project where there are users with four roles

  • 0

Currently i m working on a project where there are users with four roles who can access the same pages (there are plenty of pages with nearly 80-90 controls in each 🙁 ).

The requirement is that, depending on each role, the user should be able to view the particular controls in each page(i.e. controls visible to one role need not be visible to other role).
It looks very simple functionality and i also know that i can do it using code behind (e.g. controlname.visible=false etc.),but since there are plenty of pages with numerous controls in it which are specific to particular role it becomes very lengthy and less maintainable code.

Can any one give me best way to do this,which will be robust,well maintained code.(jQuery,Javascript solutions will also do..)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:01:15+00:00Added an answer on May 27, 2026 at 8:01 pm

    This was the really good question clicking my mind last year.. this is what i came up with, its a bit lengthy but i hope this could help..

    First you will have to take a look at ControlAdapters in Asp.net.

    http://www.asp.net/cssadapters/WhitePaper.aspx

    Overview:
    1.Create a control adapter for a control type you want to enable and disable based on roles.
    2.apply some attribute on asp.net controls, that specify which roles can access that control.

    in asp.net page try some thing like this

    <asp:TextBox ID="TextBox1" runat="server" CRAN="1"></asp:TextBox>
    

    here CRAN is my custom attribute and 1 is the roleid that can access this control on page.

    now its time to create a Control Adapter that will enable/disable this control based on roles.

    public class TextBoxAdapter:
         System.Web.UI.WebControls.Adapters.WebControlAdapter
        {
    
            protected override void OnLoad(EventArgs e)
            {
                if (this.Page is ISecurable)
                {
                    WebControl tb = this.Control as WebControl;
    
                    string roles = tb.Attributes[Constants.ControlRoleAttributeName];
                    bool result = true;
                    if (!string.IsNullOrEmpty(roles))
                    {
                        result = false;
                        string[] role = roles.Split(',');
                        foreach (string r in role)
                        {
                            if (Roles.IsUserInRole(r))
                            {
                                result = true;
                            }
                        }
    
                    }
    
                    tb.Enabled = result;
                    //tb.BackColor = Color.Red;
                }
                base.OnLoad(e);
            }
        }
    

    this is the control adapter i have created this will enable/disable the control based on roles. you can modify this show/hide control.

    you will have to register this control adapter in App_Browser folder of asp.net in a .browser file

    <browsers>
      <browser refID="Default">
        <controlAdapters>
    
         <adapter controlType ="System.Web.UI.WebControls.TextBox" adapterType="MyProject.ControlAdapter.TextBoxAdapter" />
        </controlAdapters>
      </browser>
    </browsers>
    

    Conclusion:
    You will have to only apply an attribute on element in order to show hide them. i have created adapter for Textbox you can try creating some generic adapter like WebControl/Control.

    Regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working currently on a web project where users can create image galleries
I am working on a project currently where there are SQL strings in the
I am currently working on a project where a programmer who fancied themselves a
I am working on a project where there are several types of users (students
I am currently working on a project which allows users to design a small
Working on a project where we have a Drupal 5 set-up. There are currently
I'm working on a project where users can define functions (to do things to
I am currently working on a project where I need to access a build
I am currently working in a project with developers working on three sites. One
I'm currently working on project with Haskell, and have found myself some trouble. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.