[英]Accessing a contentplaceholder on a master page
我試圖從后台隱藏Site.Master.cs的內容占位符。 我嘗試了以下方法:
ContentPlaceHolder cph = (ContentPlaceHolder)this.FindControl("MainContent");
和
ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("MainContent");
但這給了我一個錯誤,當我嘗試調試時,this.Controls有對象,但沒有“ MainContent”
如何訪問母版頁占位符控件?
由於ContentPlaceHolder
位於標記中,而您要修改的代碼位於同一頁面,因此您可以直接訪問它。
var cph = MainContent;
當然,由於它已經在范圍內,可能不需要將其分配給變量。
MainContent.Visible = false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.