Disable control in .aspx from Masterpage conditionally

Posted by miccet on Stack Overflow See other posts from Stack Overflow or by miccet
Published on 2009-06-05T09:17:38Z Indexed on 2010/04/27 10:53 UTC
Read the original article Hit count: 262

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about master-pages