Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have different pages in my project which has save button on it with different name

so i need a solution if a person has only save permission then only that button should be visible to him else it should not be visible to him

i need a common solution for all the pages save button

What I have tried:

i have tried command name in asp button but for making button visible true or false based on save permission but if a page has 2 save button then i have to call it 2 times which i want to avoid
Posted
Updated 16-May-16 2:33am
Comments
Karthik_Mahalingam 16-May-16 1:41am    
does the save button has same text in all pages ?
what is the name used in all pages ?
do you use master page?
PrakashCs.net 16-May-16 1:47am    
Create roles for user 1. Readonly 2. Modify 3. Delete when use loggedin and have only readonly access then disable save button.

You can try create a common function and have 2 parameters as (Controls and Role), below is the sample code

C#
public static class Util
   {
       public static void EnableConrol(WebControl control, string role)
       {
            switch (role)
            {
                case "Admin":
                    control.Enabled= true;
                    break;
                case "User":
                    control.Enabled= false;
                    break;
                default :
                    break;
            };
       }
   }


you can call wherever applicable.

Let me now if this solves your problem.

Regards,
Santosh
 
Share this answer
 
v2
If I get you right, you've something which logically needs to happen in Page_Load, but you want to avoid the obvious issues with duplicating that code in each case
If you don't want to change every aspx page then you can go for 'custom HTTP module', An HTTP module is called on every request in response to the BeginRequest and EndRequest events. As a result, the module runs before and after a request is processed.
Before every page load it gets called.
Check detail Walkthrough: Creating and Registering a Custom HTTP Module[^]
OR
in Global.asax you can hook up desired event in Application_PreRequestHandlerExecute
see below snippet

C#
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;

            if (context.Handler is Page)
            {
                Page page = (Page)context.Handler;
                page.Load += ...
            }
        }
    }
 
Share this answer
 
v2

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