问题描述
我工作的一个应用程序在那里我有在母版页中的一些linkbuttons。
我想显示他们根据给他们,一旦他们登录的授权。我已初步取得了所有的人都可见假,然后我检查了aspx.cs类母版页的授权。我做了链接按钮可见取决于授予用户的权利。但它使所有的链接按钮可见。相反,它应该只让他们两个看到和休息应该被隐藏。以下是从MasterPage.aspx.cs我的code:
ArrayList的arrlstUserRoles =新的ArrayList();
arrlstUserRoles =(ArrayList中)会话[角色];
对于(INT J = 0; J< arrlstUserRoles.Count; J ++)
{
如果(int.Parse(arrlstUserRoles [J]的ToString())== 1)
{
lbtnRetailer.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 2)
{
lbtnCategory.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 3)
{
lbtnCouponTemplate.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 4)
{
//lbtnStoreManagement.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 5)
{
lbtnStoreManagement.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 6)
{
lbtnContentManagement.Visible = TRUE;
}
否则,如果(int.Parse(arrlstUserRoles [J]的ToString())== 7)
{
//lbtnStoreManagement.Visible = TRUE;
}
}
您需要设置你要隐藏到假LinkButtons的知名度。
在你开始循环,设置所有LinkButtons的不可见的:
arrlstUserRoles =(ArrayList中)会话[角色];
lbtnRetailer.Visible = FALSE;
lbtnCategory.Visible = FALSE;
...
对于(INT J = 0; J< arrlstUserRoles.Count; J ++)
{
如果(int.Parse(arrlstUserRoles [J]的ToString())== 1)
{
lbtnRetailer.Visible = TRUE;
}
...
}
I am working on an app where i am having some linkbuttons in master page.
I want to display them depending upon the authorization given to them once they logs in. I have initially made all of them visible false and then i am checking the authorisation in the aspx.cs class of master page. I make the link button visible depending upon the right granted to the user. But it is making all the link buttons visible. Instead it should only make two of them visible and rest should be hidden. Following is my code from MasterPage.aspx.cs:
ArrayList arrlstUserRoles = new ArrayList();
arrlstUserRoles = (ArrayList)Session["Roles"];
for (int j = 0; j < arrlstUserRoles.Count; j++)
{
if (int.Parse(arrlstUserRoles[j].ToString()) == 1)
{
lbtnRetailer.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 2)
{
lbtnCategory.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 3)
{
lbtnCouponTemplate.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 4)
{
//lbtnStoreManagement.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 5)
{
lbtnStoreManagement.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 6)
{
lbtnContentManagement.Visible = true;
}
else if (int.Parse(arrlstUserRoles[j].ToString()) == 7)
{
//lbtnStoreManagement.Visible = true;
}
}
You need to set the visibility of the LinkButtons you want to hide to false.
Before you start looping, set all of the LinkButtons to not be visible:
arrlstUserRoles = (ArrayList)Session["Roles"];
lbtnRetailer.Visible = false;
lbtnCategory.Visible = false;
...
for (int j = 0; j < arrlstUserRoles.Count; j++)
{
if (int.Parse(arrlstUserRoles[j].ToString()) == 1)
{
lbtnRetailer.Visible = true;
}
...
}
这篇关于在母版页隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!