2008-10-10 66 views
5

是否可以通过代码设置ContentPlaceHolder中的数据?这是我想到的是:通过代码设置ContentPlaceHolder数据ASP.NET

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 

显然,这是不正确的语法,我希望这个澄清什么,我问。

回答

6

您应该可以通过当前页面上的MasterPage元素来引用它。例如:

ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl("column1"); 

如果在MasterPage代码隐藏中,只需引用它的名称即可。