开发者

hiding buttons in master page

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["Rol开发者_开发技巧es"];
                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;
   }
   ...

  }  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜