簡體   English   中英

在母版頁上找到母版頁控件后如何添加屬性?

[英]how to add attributes after finding master page controls on master page?

我的母版頁中有一些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的新手

只需使用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");

剛剛測試。 兩者都在我的母版頁上為我工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM