Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Set Enabled to false for multiple web controls

Reply
Thread Tools

Set Enabled to false for multiple web controls

 
 
elaine
Guest
Posts: n/a
 
      05-24-2007
Hi,

I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :

for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}

Anyone can give me a hint?

Elaine

 
Reply With Quote
 
 
 
 
Olorin
Guest
Posts: n/a
 
      05-24-2007
On May 23, 9:01 pm, elaine <(E-Mail Removed)> wrote:
> But there should be a easy way to do it
> like :
>
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
>
> }
>
> Anyone can give me a hint?


Sorry, I'm not clear on your question...
...do you mean that the for loop you wrote up there doesn't work ?
If it does, that seems fairly simple to me.. maybe I'd try to save a
line with:

foreach(Control ctrl in this.Controls)
ctrl.Enabled=false;

However, I don't think that the base Control class defines an Enabled
property, and that might be a problem. Then again, a Control might be
a label, a text literal, a generic html control, a bunch of things
were it's not quite clear what it means to be 'enabled' or not. Maybe
when 'enabled' is turned to false on your user control, you just don't
want to display any of its children controls ?
If so, at render time, you could check the value of the user control's
Enabled property:

if(this.Enabled)
base.Render(writer);

HTH,
~O

 
Reply With Quote
 
 
 
 
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
Guest
Posts: n/a
 
      05-24-2007
You could use control tree recursion to touch all the controls in the way
you describe.
Here are the details:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net


"elaine" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
>
> I have a usercontrol which contains multiple server controls like
> textbox, radiobutton..., I have a public field in the usercontrol
> "Enabled". What i want to do is when the usercontrol's "Enabled" is
> set to false, set all its child controls "Enabled" to false. I know i
> can set them one by one. But there should be a easy way to do it
> like :
>
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
> }
>
> Anyone can give me a hint?
>
> Elaine
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM
Enabled set to false but still able to use datagrid Dave E ASP .Net Datagrid Control 1 02-15-2005 05:49 AM
How Do I set enabled to false on all but one web control on a page Karen Grube ASP .Net Web Controls 0 11-24-2004 08:35 PM
Setting the web control textbox property enabled = FALSE Gill Smith ASP .Net 4 05-22-2004 08:20 PM
Enabled = False disables controls on all pages. Why? Bisser Milanov ASP .Net Web Controls 0 07-13-2003 11:53 AM



Advertisments