我目前正在学习在 ASP.NET 3.5 和 C# 中使用 MasterPages 和 ContentPlaceHolders - 现在,我正在拼命尝试通过我的编程代码编辑 asp:Content-Control 的内容。
背景是这个;一旦按下按钮,我希望清除 asp:Content 并通过 *.cs-File 填充动态生成的内容。
但我无法弄清楚如何访问 asp:Content-Control,无论是通过其 ID 还是 Page.FindControl 等。
那么,如何通过编程代码编辑 asp:Content-Control 的内容呢?
最佳答案
您可以通过不在页面对象上而是在其母版页上使用 FindControl 来访问 ContentPlaceholder。
System.Web.UI.MasterPage masterPage = this.Master;
ContentPlaceHolder pageContent;
pageContent = (ContentPlaceHolder)masterPage.FindControl("YourContentPlaceholderName");
我同意最好在这个 block 中定义一个面板或占位符并直接访问它,而不是尝试修改 ContentPlaceholder
关于c# - 设置 <asp :content> content in C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1686732/