2008-10-10 63 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代碼隱藏中,只需引用它的名稱即可。