通过代码ASP.NET设置ContentPlaceHolder数据

And*_*ers 5 asp.net contentplaceholder

是否可以通过代码在ContentPlaceHolder中设置数据?这就是我的想法:

dim oCPH as new ContentPlaceHolder
oCPH.id = "column1" 'this id is the one that corresponds with the ID I set on the page
oCPH.content = "content here" '<-- not real code
Run Code Online (Sandbox Code Playgroud)

显然这不是正确的语法,我希望这澄清了我的要求.

tva*_*son 6

您应该能够通过当前页面上的MasterPage元素引用它.就像是:

ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl("column1");
Run Code Online (Sandbox Code Playgroud)

如果在MasterPage代码隐藏中,只需按名称引用它.