Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a project around 250 screens. In each screen there are multiple buttons like New, Save, Delete and close.

When a user login to the application we are giving the access privileges to the user for the navigation through the application.

Now we want to enable the access privilege to the user for the buttons also. Example an user can able to save the record but not able to delete it.

What I have tried:

What is the best way to approach it globally . By using a function. Right now, we are writing the privileges in each and every page to disable the button.
Posted
Updated 4-Apr-18 1:42am
v2
Comments
F-ES Sitecore 4-Apr-18 4:35am    
Webforms? MVC?
Member 13142345 4-Apr-18 4:37am    
Webforms

Right, just IGNORE ME. Thought it was winforms. What an idiot...


I can suggest how I'd go about it. First off, I'd work out what the permissions are and decide on which buttons rely on which permissions, and what permissions each user has. You could just hard-code this or do something more elaborate.

Then, some sort of global method which iterates over the buttons on the form and selectively disables them. My inclination would be to create a derived class of Form with this method in it, then do a global search and replace on all existing form code to derive from this one. Keeps it neat and in one place.

In this method, you iterate over the child controls, check if they're buttons and check their permission. You could do this perhaps by putting something in the tag property to denote the permission. Call the method from the Load() method.

Alternatively, if the buttons are just vanilla, you could create a button subclass, say PermissionButton and again to a global search and replace to use this rather than the standard. I'm not quite sure what method you'd override to disable, perhaps activate or something like that.

So basically do it one place, by using a derived form or a derived button.
 
Share this answer
 
v3
Hi, one easy way to achive this is to use a base class for all your forms.
You can then use somthing like this to disable any type of control you want in your base class Page_Load event.


C#
protected void Page_Load(object sender, EventArgs e)
{
  DisableChilds(this.Page);
}

 private void DisableChilds(Control ctrl)
        {
            foreach (Control c in ctrl.Controls)
            {
                DisableChilds(c);
                if (c is Button)
                {
                    ((Button)(c)).Enabled = false;
                }
            }
        }

You can replace the Button control with any other control.
I dont have any idea about performance, but it is probably heavy since its recursive!

I think there is another method that allows you to get all controls in a page, i cant remember it ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900