Can I hide a user control on the main page from the content page?

How to hide user control on home page from content page? This is the code that I have on loading my page.

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

Nothing for me: (

+3
source share
1 answer

Display the visible property of the user control using the property MasterPage.

In MasterPage:

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

Then be sure to add a link to your content page:

<%@ MasterType TypeName="YourMasterPageTypeName" %>

Then, on your content page, simply do:

Master.MyBannerVisibility = false;

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

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
+2

Source: https://habr.com/ru/post/1751833/


All Articles