Here what I did and it's very useful
In web.config add this
<configuration>
<appSettings>
<add key="Default.aspx" value="true"/>
<add key="HomeLHA.aspx" value="true"/>
<add key="Analytics.aspx" value="true"/>
<add key="Links.aspx" value="false"/>
</appSettings>
</configuration>
and wrote a method
public void ddlDynamicVisible(string PageName, DropDownList ddlDynamic)
{
if (ddlDynamic != null)
{
String isVisible = string.Empty;
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
if (appSettingsSection != null)
{
foreach (string key in appSettingsSection.Settings.AllKeys)
{
if (key == PageName)
{
isVisible = System.Configuration.ConfigurationManager.AppSettings[key];
ddlDynamic.Visible = Convert.ToBoolean(isVisible);
}
}
}
}
}
make a call to this method from each page where you want to display or hide control
public partial class Links : System.Web.UI.Page
{
DropDownList ddlDynamic;
protected void Page_Load(object sender, EventArgs e)
{
ddlDynamic = (DropDownList)Master.FindControl("ddlDynamic");
CustomMethods Methods = new CustomMethods();
Methods.ddlDynamicVisible(Path.GetFileName(Request.PhysicalPath), ddlDynamic);
}
}
now this dropdown will only be available on pages where you set True in web.config.
Thanks,
Enjoy coding.