如果他没有保存权限,如何禁用项目中不同页面上的所有按钮 [英] How to disable all button on different page in a project if he does not save permission
问题描述
我的项目中有不同的页面,上面有不同名称的保存按钮
所以我需要一个解决方案,如果一个人只有保存权限那么只有那个按钮应该是他可见的,否则它不应该对他可见
i需要所有页面的通用解决方案保存按钮
我尝试了什么:
i在asp按钮中尝试了命令名,但是为了使按钮可见为真或假在保存权限但如果一个页面有2个保存按钮然后我必须调用它2次我想避免
你可以尝试创建一个共同的功能,并有2个参数为(控件和角色),下面是示例代码
public static class Util
{
public static void EnableConrol(WebControl控件,字符串角色)
{
开关(角色)
{
案例 Admin:
control.Enabled = true < /跨度>;
break ;
case 用户 :
control.Enabled = false ;
break ;
默认:
break ;
};
}
}
您可以在适用的地方致电。
现在让我来解决你的问题。
问候,
Santosh
< blockquote>如果我说得对,你在Page_Load中有一些逻辑上需要的东西,但是你想避免在每种情况下重复代码的明显问题
如果你不想更改每个aspx页面然后你可以去'自定义HTTP模块',每个请求都会调用一个HTTP模块来响应BeginRequest和EndRequest事件。因此,模块在处理请求之前和之后运行。
每次加载页面之前都会调用它。
查看详细信息演练:创建和注册自定义HTTP模块 [ ^ ]
或
在Global.asax中你可以在Application_PreRequestHandlerExecute中挂钩所需的事件
见下面的片段< br $> b $ b
void Application_PreRequestHandlerExecute( object sender,EventArgs e)
{
HttpApplication application =(HttpApplication)sender;
HttpContext context = application.Context;
if (context.Handler 页面)
{
页页=(页面)context.Handler;
page.Load + = ...
}
}
}
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
You can try create a common function and have 2 parameters as (Controls and Role), below is the sample code
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
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
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 += ... } } }
这篇关于如果他没有保存权限,如何禁用项目中不同页面上的所有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!