【问题标题】:how to add attributes after finding master page controls on master page?在母版页上找到母版页控件后如何添加属性?
【发布时间】:2019-09-12 21:12:46
【问题描述】:

我的母版页中有一些 LIST 控件到该列表中,如果他是管理员或用户等,我想根据某些标准从母版页后面的代码中添加属性,例如 href 属性。 我试过了

Control mycontrol=FindControl(v.Item1) ///v.Item1 im getting from database which is actual id of control in my aspx code
mycontrol.Attributes.Add("href","~/sales.aspx")/// this is not working

请帮助我是 asp.net 的新手

【问题讨论】:

    标签: c# asp.net master-pages


    【解决方案1】:

    只需使用 HTMLAnchor 或 HTML 控件

               //Example 1
                HtmlAnchor ct = (HtmlAnchor)FindControl("CRM1");
                ct.Attributes.Add("href", "~/Test.aspx");
    
                //Example 2
                HtmlControl ct2 = (HtmlControl)Page.Master.FindControl("CRM2");
                ct2.Attributes.Add("href", "~/Test.aspx");
    

    刚刚测试过。两者都在我的母版页中为我工作

    【讨论】:

    • 如果对您有帮助,请将评论标记为答案。
    猜你喜欢
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多