Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Disable all controls in...

Reply
Thread Tools

Disable all controls in...

 
 
Edwin Knoppert
Guest
Posts: n/a
 
      01-22-2006
I have a div which holds controls.
I'm looking for a way to disable all controls but *without* setting each
control enable state.
Same to style>display i'm looking for a disable method.

Do i need a container control for this?


 
Reply With Quote
 
 
 
 
Peter McMahon
Guest
Posts: n/a
 
      01-22-2006
Hi Edwin,

Yes, using a Panel WebControl would probably be a good way to solve your
problem.

Groete,
Peter

Peter McMahon
http://www.dotnet.za.net

"Edwin Knoppert" <(E-Mail Removed)> wrote in message
news:dr0tpb$99r$(E-Mail Removed)...
>I have a div which holds controls.
> I'm looking for a way to disable all controls but *without* setting each
> control enable state.
> Same to style>display i'm looking for a disable method.
>
> Do i need a container control for this?
>
>



 
Reply With Quote
 
 
 
 
Andrew Robinson
Guest
Posts: n/a
 
      01-23-2006
You can use a container control or make the div a server side control:

<body>
<form id="form1" runat="server">

<div id="div1" runat="server">

<asp:TextBox ID="TextBox1" runat="server" />

<asp:Button ID="Button1" runat="server" />

</div>

</form>

</body>

div1.Visible = false;


--
Andrew Robinson
http://blog.binaryocean.com


"Edwin Knoppert" <(E-Mail Removed)> wrote in message
news:dr0tpb$99r$(E-Mail Removed)...
>I have a div which holds controls.
> I'm looking for a way to disable all controls but *without* setting each
> control enable state.
> Same to style>display i'm looking for a disable method.
>
> Do i need a container control for this?
>
>



 
Reply With Quote
 
Edwin Knoppert
Guest
Posts: n/a
 
      01-23-2006
Thanks, will check!




"Peter McMahon" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hi Edwin,
>
> Yes, using a Panel WebControl would probably be a good way to solve your
> problem.
>
> Groete,
> Peter
>
> Peter McMahon
> http://www.dotnet.za.net
>
> "Edwin Knoppert" <(E-Mail Removed)> wrote in message
> news:dr0tpb$99r$(E-Mail Removed)...
>>I have a div which holds controls.
>> I'm looking for a way to disable all controls but *without* setting each
>> control enable state.
>> Same to style>display i'm looking for a disable method.
>>
>> Do i need a container control for this?
>>
>>

>
>



 
Reply With Quote
 
Edwin Knoppert
Guest
Posts: n/a
 
      01-23-2006
I did the same, like i said, visible does work, disabling instead.. how?



"Andrew Robinson" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> You can use a container control or make the div a server side control:
>
> <body>
> <form id="form1" runat="server">
>
> <div id="div1" runat="server">
>
> <asp:TextBox ID="TextBox1" runat="server" />
>
> <asp:Button ID="Button1" runat="server" />
>
> </div>
>
> </form>
>
> </body>
>
> div1.Visible = false;
>
>
> --
> Andrew Robinson
> http://blog.binaryocean.com
>
>
> "Edwin Knoppert" <(E-Mail Removed)> wrote in message
> news:dr0tpb$99r$(E-Mail Removed)...
>>I have a div which holds controls.
>> I'm looking for a way to disable all controls but *without* setting each
>> control enable state.
>> Same to style>display i'm looking for a disable method.
>>
>> Do i need a container control for this?
>>
>>

>
>



 
Reply With Quote
 
Andrew Robinson
Guest
Posts: n/a
 
      01-23-2006
Edwin,

Only ASP.NET server controls contain the Enabled property. If you are using
all server side controls, you can do the following:

<body>
<form id="form1" runat="server">
<div>
<asplaceHolder ID="PlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</asplaceHolder>
</div>
</form>
</body>

in code:

foreach (WebControl control in PlaceHolder1.Controls)
{
control.Enabled = false;
}

If you attempt to use this with an HTML control such as an <IMG> or <INPUT>
tag, you will throw an InvalidCastException.

Hope this helps.

--

Andrew Robinson
http://blog.binaryocean.com

"Edwin Knoppert" <(E-Mail Removed)> wrote in message
news:43d497ec$0$12844$(E-Mail Removed) ...
>I did the same, like i said, visible does work, disabling instead.. how?
>
>
>
> "Andrew Robinson" <(E-Mail Removed)> schreef in bericht
> news:%(E-Mail Removed)...
>> You can use a container control or make the div a server side control:
>>
>> <body>
>> <form id="form1" runat="server">
>>
>> <div id="div1" runat="server">
>>
>> <asp:TextBox ID="TextBox1" runat="server" />
>>
>> <asp:Button ID="Button1" runat="server" />
>>
>> </div>
>>
>> </form>
>>
>> </body>
>>
>> div1.Visible = false;
>>
>>
>> --
>> Andrew Robinson
>> http://blog.binaryocean.com
>>
>>
>> "Edwin Knoppert" <(E-Mail Removed)> wrote in message
>> news:dr0tpb$99r$(E-Mail Removed)...
>>>I have a div which holds controls.
>>> I'm looking for a way to disable all controls but *without* setting each
>>> control enable state.
>>> Same to style>display i'm looking for a disable method.
>>>
>>> Do i need a container control for this?
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
dayalaman dayalaman is offline
Junior Member
Join Date: Dec 2007
Posts: 1
 
      12-04-2007
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;
   }
}
=============


I have more posts like these on rudebox.editboard.com <- My forum
 

Last edited by dayalaman; 12-04-2007 at 12:54 AM..
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
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
Enable/disable all controls on a web page disaia@earthlink.net ASP .Net 4 08-01-2006 11:50 PM
basic: asp.net user controls: how to programmatically add attribute to all text box controls? ASP .Net 4 11-09-2005 02:14 AM
Disable all form controls Evan M. ASP .Net Web Controls 2 08-18-2005 08:26 PM
disable all elements from all forms except <textarea>'s Bart Van der Donck Javascript 3 02-01-2005 08:22 PM



Advertisments