Disable all controls in...

  • Thread starter Thread starter Edwin Knoppert
  • Start date Start date
E

Edwin Knoppert

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?
 
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;
 
I did the same, like i said, visible does work, disabling instead.. how?
 
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>
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:PlaceHolder>
</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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top