【问题标题】:How to access <asp:placeholder> in other tags如何在其他标签中访问 <asp:placeholder>
【发布时间】:2016-11-20 01:32:36
【问题描述】:

我的页面上有一个导航栏。

<ul>
  <li><asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder></li>
  <li>Register</li>
  <li>Login</li>
</ul>

现在在我的 webpage.cs 文件中访问另一个 Placeholder,就像这样

PlaceHolder1.Controls.Add(new Literal{Text = li.ToString()};

li 这是我之前声明的StringBuilder
这个PlaceHolder1body 的导航栏之外,我可以访问它但是我怎样才能访问导航栏中的PlaceHolder2

【问题讨论】:

  • PlaceHolder2.Controls.Add(new Literal{Text = "Another link"};怎么样
  • 没有这个当我输入 PlaceHolder2 其 ID 视觉工作室说 Placeholder2 在当前上下文中不存在
  • 可能PlaceHolder2MasterPage 文件中,但不在页面本身中?

标签: c# html asp.net web


【解决方案1】:
(PlaceHolder1.FindControl("PlaceHolder2") as PlaceHolder)

【讨论】:

  • 我不明白你能解释更多吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
  • 2011-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多