【问题标题】:Hide <li> asp.net items depending on user privileges根据用户权限隐藏 <li> asp.net 项目
【发布时间】:2016-05-01 22:02:58
【问题描述】:

当特定用户登录网站时,我必须隐藏第 4 列。这是我当前的 asp 和 c# 代码:

protected void Page_Load(object sender, EventArgs e)
        {
            ((LoggedIn)Page.Master).CurrentPage = LoggedIn.LoggedInMenuPages.1;

            if (CurrentCustomer.AdminRole==false)
            {
               ******NEED TO HIDE ITEM 4
            }
        }

【问题讨论】:

    标签: c# asp.net list hide


    【解决方案1】:

    runat="server" 放入元素中,并指定ID,然后输入Page_Load 写入ControlID.Visible=false

    ASPX

    <li id="AdminElement" runat="server">
     //other tags
    </li>
    

    Page_Load

     AdminElement.Visible = CurrentCustomer.AdminRole;
     //remove the class attribute from the aspx
     AdminElement.Attributes["class"] = GetCurrentPageStyle("4");       
    

    【讨论】:

    • 我在发布此问题之前尝试过这样做,但 Visual Studio 返回以下错误:解析服务此请求所需的资源时发生错误。请查看以下特定的解析错误详细信息并适当地修改您的源文件。解析器错误消息:服务器标签不能包含 构造。
    • @m_wilson 所以也要在 Page_Load 中设置 li 元素的 class 属性。从 aspx 和 Page_Load 中将其删除,例如 AdminElement.Attributes["class"] = GetCurrentPageStyle("4");
    • 谢谢!我实际上是在放置 AdminElement.Attributes["class"] = GetCurrentPageStyle("4");和 AdminElement.Visible = false;进入错误的 Page_load...多么愚蠢。
    • 别担心,愚蠢的错误会发生在每个人身上,祝你的项目好运。
    猜你喜欢
    • 2011-06-24
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多