views:

456

answers:

1

I've been reading the other questions dealing with master pages, but I didn't see any that quite had the answer I'm looking for, so...

I have a master page. I have a control(Control A) on the master page. I have a certain content page that I want to disable (Control A) and enable (Control B).

Instead of doing this on the content page, I would like to do this in a static utility class that I am using in the site. The reason for this is that we have 4 different sections on the website that use 4 different master pages. I'm trying to create a static method that receives the name of the master page and the control and then swaps the controls.

I can't quite figure out how to reference the master page from a separate class.

Thanks for any help you can offer.

+2  A: 

I don't think you'll be able to do that... presumably you want something like

public static void DoWork (string masterPageName) { //Code to find instance of masterpage... }

You won't be able to do that from a static class as there is no instances. You'd need to find it outside and pass the actual master page object into your Static Method.

I don't really see why it's necessary to do this in a utility class though if it's specific to one of your content pages. If it's generic to many of your content pages, then consider creating a basePage class that your content pages can extend... e.g.

public class BasePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if(this.Master != null)
          if(this.Master.FindControl("Control A") != null)
              //Disable Control A
              //Enabled Control B
    }
}
Eoin Campbell