R – Disable control in .aspx from Masterpage conditionally

asp.netmaster-pages

Ok, this might be a bit weird, so I'll start with explaining what I'm trying to do. I have several masterpages for my site, and in they inherit each other. In the second of them (4 in total) I have a background image. Here comes the trick, I'd like to override this image from the final aspx page. I can't change the position of this image, it has to be in masterpage 2, since some pages uses that very page as masterpage.

One idea I had was to create a ContentPlaceHolder next to the image and if there are any images in that (check in Page_Load) then the main image would be hidden. I did this with a recursive function, that finds the image by looping through the ContentPlaceHolder's controls. When I set the visibility property to false though, nothing happens.

Any other ideas to how this could be done, or why the above doesn't work?

Edit: It's not about changing items in the master pages, rather the other way around, that from the Masterpages codebehind dig down into the page that is displayed currently and see if it has controls in a specific ContentPlaceHolder.

Best Answer

i've managed to access controls on a master page like this:

        Control control = Master.FindControl("ControlID");
        if (control is ControlType)
        {
            ControlType menu = control as ControlType;
            menu.Visible = false;
        }

not sure if that will help with your problem specifically.

Related Topic