Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET web.Config
Hi,
 
I am developing an application with four menu items/pages (Default.aspx, Links.aspx, Analytics.aspx and AddNewTab.aspx) and a dropdown list on Site.Master page.
 
How I can hide dropdown list from Analytics.aspx and Links.aspx pages through web.config, where as have that available on Default.aspx and AddNewTab.aspx pages.
Posted 5-Jul-13 12:06pm
Edited 5-Jul-13 12:24pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here what I did and it's very useful
In web.config add this
<configuration>
  <appSettings>
    <!-- Dynamic Drop down list keys-->
    <add key="Default.aspx" value="true"/>
    <add key="HomeLHA.aspx" value="true"/>
    <add key="Analytics.aspx" value="true"/>
    <add key="Links.aspx" value="false"/>
    <!-- Dynamic Drop down list keys-->
  </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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i think it will be the best idea to remove the unwanted controls from master page like below
I assume that your dropdown list control is runat='server' then, You could do this on your page where you want to remove that dropdown list:
System.Web.UI.HtmlControls.HtmlGenericControl DropDownList=
                             this.Master.FindControl("dropdownlistID") as 
                             System.Web.UI.HtmlControls.HtmlGenericControl;
     this.Master.Controls.Remove(DropDownList);
 
hope it will help you
  Permalink  
v3
Comments
zunorain at 11-Jul-13 10:54am
   
Thanks for the solution, but it will only remove it through code what if this need to be display or hide through web.config.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here what I did and it's very useful
In web.config add this
 
<configuration>
  <appSettings>
    <!-- Dynamic Drop down list keys-->
    <add key="Default.aspx" value="true"/>
    <add key="HomeLHA.aspx" value="true"/>
    <add key="Analytics.aspx" value="true"/>
    <add key="Links.aspx" value="false"/>
    <!-- Dynamic Drop down list keys-->
  </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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100