Nil Pun
Nil Pun

Reputation: 17373

ASP.NET Server Controls Tag for Role Based Authorization

I've got a web form with lots fields and buttons. These fields and buttons should be enabled and disabled based on users Role i.e. 'employee', 'team leader', 'manager' etc.

Is there a way to tag each fields such as emp for employee, tm for teamleader so that I can enable or disable them with 1 or 2 lines of code?

Otherwise I will have to write lots of if else statement for each controls.

thank you

Upvotes: 1

Views: 158

Answers (1)

SLaks
SLaks

Reputation: 887797

You can create WebControl[] arrays in the code-behind containing the controls visible to each role:

WebControl[] managerControls = { someControl, otherButton, ... };

Upvotes: 1

Related Questions