Asp.net

如何在 ASP.net 的頁面中獲取母版頁的 Div?

  • February 20, 2013

我在我的 Web 應用程序中使用母版頁。現在我正在創建多個內容頁面。母版頁中有一個帶有標籤的 Div。現在我想將該 Div 隱藏在一個內容頁面中,而其他內容頁面中的其他要求是獲取 Div 內部的標籤。

那麼如何從內容頁面隱藏母版頁中的 Div 以及如何從內容頁面獲取該 Div 中定義的標籤?

在母版頁中的 div 中添加屬性:runat="server" 然後在內容頁中編寫以下程式碼來訪問該 div:

    Control c=  this.Master.FindControl("masterDiv");// "masterDiv"= the Id of the div.
    c.Visible = false;//to set the div to be hidden.

祝你好運!

引用自:https://stackoverflow.com/questions/10186295