【问题标题】:Get the <a> element in the Site.Master in another content page?在另一个内容页面中获取 Site.Master 中的 <a> 元素?
【发布时间】:2022-09-27 20:20:21
【问题描述】:

我的网站表单中有一个 HTML 元素 &lt;a&gt;。我是这样设计的:

<li>
    <a  runat=\"server\" id=\"sbHome\" href=\"Dashboard.aspx\" class=\"dropdown-toggle no-arrow\">
        <span class=\"micon bi bi-house\"></span><span class=\"mtext\">Home</span>
   </a>
</li> 

我正在尝试在我的仪表板中获取sbHome,以便在我的代码后面将其设置为活动状态,就像这样。

 HtmlGenericControl aControl = Master.FindControl(\"sbHome\") as HtmlGenericControl;
 if (aControl != null)
 {
    aControl.Attributes.Clear();
    aControl.Attributes.Add(\"class\", \"dropdown-toggle no-arrow active\");             
 }

然而,Master.FindControl 方法返回 null。我怎么可能得到这个元素 从我的内容页面?

    标签: c# html webforms


    【解决方案1】:

    您是否尝试过使用超链接控件而不是&lt;a&gt;?正要对此发表评论,但我的声誉低于 50,希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 2011-06-30
      • 1970-01-01
      相关资源
      最近更新 更多