Accessing the Control main page from a separate class
I have read other master pages related questions but I have not seen that I have the answer I am looking for, so ...
I have a home page. I have a control (Control A) on the home page. I have a specific content page that I want to disable (Control A) and enable (Control B).
Instead, in the content page, I would like to do it in a static class that I am using on the site. The reason for this is that we have 4 different sections on the site that use 4 different master pages. I am trying to create a static method that gets the name of the master page and control and then replaces the controls.
I cannot figure out how to link to the master page from a separate class.
a source to share
I don't think you can do this ... presumably you want something like
public static void DoWork (string masterPageName)
{
//Code to find instance of masterpage...
}
You won't be able to do this from a static class as there are no instances. You will need to find it outside and pass the master page object to your static method.
I really don't understand why this needs to be done in the utility class, but if it is for one of your content pages. If it is common to many of your content pages, consider creating a basePage class that your content pages can extend ... for example
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
}
}
a source to share