我的母版页中有一些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的新手
答案 0 :(得分: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");
刚刚测试。两者都在我的母版页上为我工作