Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>lets say you have your control ids loaded into a string[]</p> <p>Try : </p> <pre><code>protected class ControlDescription { public string Name { get; set; } public bool isVisible { get; set; } public bool isEnabled { get; set; } public ControlDescription(string _name, int vis, int ena) { this.Name = _name; this.isVisible = (vis == 1); this.isEnabled = (ena == 1); } } protected void Page_Load(object sender, EventArgs e) { List&lt;ControlDescription&gt; CDescriptions = new List&lt;ControlDescription&gt;(); //loop through data from database //{ //ControlDescription C = new ControlDescription(name,int,ena); //CDescriptions.Add(C); //} foreach (ControlDescription C in CDescriptions) { Control Ctrl = this.FindControl(C.Name); if (Ctrl != null) { //Ctrl.Visible = C.isVisible; DisableControls(Ctrl); //if (Ctrl is WebControl) // ((WebControl)Ctrl).Enabled = C.isEnabled; HideControls(Ctrl); } } } </code></pre> <p>EDIT : Based on your comment you may not know the type of your control is not always a webcontrol or not a subclass necessarily, i added 2 more functions and used them in the code up there instead of the existing code.</p> <pre><code>private void DisableControls(System.Web.UI.Control control) { foreach (System.Web.UI.Control c in control.Controls) { // Get the Enabled property by reflection. Type type = c.GetType; PropertyInfo prop = type.GetProperty("Enabled"); // Set it to False to disable the control. if ((prop != null)) { prop.SetValue(c, false, null); } // Recurse into child controls. if (c.Controls.Count &gt; 0) { this.DisableControls(c); } } } private void HideControls(System.Web.UI.Control control) { foreach (System.Web.UI.Control c in control.Controls) { // Get the Enabled property by reflection. Type type = c.GetType; PropertyInfo prop = type.GetProperty("Visible"); // Set it to False to disable the control. if ((prop != null)) { prop.SetValue(c, false, null); } // Recurse into child controls. if (c.Controls.Count &gt; 0) { this.HideControls(c); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload