开发者

Can I hide a user control in a master page from a content page?

How can I 开发者_C百科hide a user control on the master page from a content page? This is code I have on my content page's load.

    Dim banner As UserControl = DirectCast(Master.FindControl("uc_banner1"), UserControl)
    banner.Visible = True

Does nothing for me :(


Expose the visible property of the user control via a property of the MasterPage.

In your MasterPage:

public bool MyBannerVisibility
{
    get { return uc_banner1.Visible; }
    set { uc_banner1.Visible = value; }
}

Then make sure to add a reference in your content page:

<%@ MasterType TypeName="YourMasterPageTypeName" %>

Then in your content page just do:

Master.MyBannerVisibility = false;

Edit: Since your using VB.net I used a code converter to convert it for you:

Public Property MyBannerVisibility() As String
    Get
        Return uc_banner1.Visible
    End Get
    Set
        uc_banner1.Visible = value
    End Set
End Property

Content Page:

Master.MyBannerVisibility = False
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜