Admin Admin

Number of posts: 206 Registration date: 2007-01-01
 | Subject: Enable Disable, all controls in a div / placeholder Tue Dec 04, 2007 12:49 am | |
| ASPX Page:| Code: | <asp:PlaceHolder ID="placeHolderMyServerControl" runat="server"></asp:PlaceHolder> |
Code Behind:
Call Function:
| Code: |
private bool condition;
protected override void CreateChildControls() { base.CreateChildControls(); MyServerControl serverControl = new MyServerControl(); placeHolderMyServerControl.Controls.Add(serverControl); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); MyCondition(); if(condition == true) { EnableControl(true, placeHolderMyServerControl.Controls); } else { EnableControl(false, placeHolderMyServerControl.Controls); } }
| Create Function:
| Code: | /// <summary> /// Enable Disable Control /// </summary> /// <param name="enabled">true or false</param> /// <param name="controls">Controls Collection</param> private void EnableControl(bool enabled, ControlCollection controls) { foreach (Control childControl in control) { try { WebControl webChildControl = (WebControl) childControl; webChildControl.Enabled = enabled; } catch { } finally { EnableControl(enabled, childControl.Controls); } } }
//Your Condition private void MyCondition() { //Put your own if condition if() { condition = true; } else { condition = false; } }
|
============= |
|