hiding buttons in master page

青春壹個敷衍的年華 提交于 2019-12-11 16:24:44

问题


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

回答1:


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

  }  


来源:https://stackoverflow.com/questions/2369798/hiding-buttons-in-master-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!