views:

134

answers:

1

Hi,

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;
                    }
                }  
A: 

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;
   }
   ...

  }  
Oded
that was a very stupid mistake that i have made, thanks for pointing my mistake
pankaj