views:

663

answers:

3

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.

A: 

Maybe this article will point you in the right direction: http://stackoverflow.com/questions/952771/masterpage-submasterpage-web-form-getting-properties-of-masterpage-in-sub-p

Joop
+1  A: 

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.

Stephen Binns
A: 

Thank you Stephen,

I managed like disabling Treeview while loading master page with defaultpage.aspx.I placed treeview in ContentPlaceHolder with id="cphtv" and treeview id :TreeView1

Control control1 = Master.FindControl("cphtv");
if (control1 is ContentPlaceHolder)
{
    Label5.Text = "ContentPlaceHolder found";
    Control tc = control1.FindControl("TreeView1");
    if (tc is TreeView)
    {
        tc.Visible = false;
        Label6.Text = "tree view false";
    }
    else{
        Label6.Text = "tree view control  not found";

    }

}
else
{
    Label6.Text = "not found";
}
lokesh