Changing master page elements from content page in vb.net

I have a page named a1.aspx, with Masterpagefile = a1_master.master. The main page now has its own divs and images for design purposes. I want that when I load a1.aspx some selected and images should be hidden (visible = false). How can i do this? how can I change the visibility of a div or image on the master page from the content page?

+2


a source to share


3 answers


Declare the interface for your main page like this:

interface IMasterPageControls{
 Image MyImage { get; }
}

      

& execute it on the main page:

public class MasterPage : IMasterPageControls{
 public Image MyImage {
   get {  
     // whatever it takes to get the correct object...
     return (Image)this.Page
                           .FindControl("nameOfContainer")
                           .FindControl("nameOfImage");
   }
 }
}

      



& then in your page you can do:

Image img = (this.Master as IMasterPageControls).MyImage;

      

this will give you a handle to the image and fix some of the problems that @Matthew mentions ...

NTN

+1


a source


Perhaps you want to use FindControl and Master, for example:

Image myImage = (Image)Master.FindControl("nameOfImage");
myImage.Visible = false;

      



Check this MSDN page for more information and samples .

0


a source


Create a property for the master page

public partial class YourMasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    { }

    public bool HideImage
    {
        get { return imgYourImage.Visible; }
        set { imgYourImage.Visible = value; }
    }
}

      

On your content page:

(this.Master as YourMasterPage).HideImage = true;

      

0


a source







All Articles