Iterating Controls on ContentPlaceHolder

G

Guest

Hi,

I am trying to iterate though the controls on a content page that has a
master page so I can disable text. If it weren't on a content page it is
simple:

foreach (Control c in Page.Controls)
{
if (c is TextBox)
{
(TextBox)c.Enabled = false;
}
}

I can't figure out how to get the ClientID into this to deal with the
mangled names.

thanks,
Bill
 
B

Bruce Barker

as controls are nested in controls, you need to recurse thru all controls

void DisableAllTextBoxes(Control ctl)
{
if (ctl is TextBox)
(TextBox) ctl.Enabled = false;
foreach (Control c in ctl.Controls)
{
DisableAllTextBoxes(c);
}
}

-- bruce (sqlwork.com)
 
G

Guest

Hi Bruce,

Thanks much for the quick reply. I'm not sure what control to pass in to
begin the recursion. The problem with the example that I gave is that
Page.Controls seems to be looking at the master page rather than the content
page where the controls are that I want to disable. Also, if I place this
function in my code beside it give a compile error:
Error 23 'System.Web.UI.Control' does not contain a definition for
'Enabled' C:\KEY\KPO\BZP\AuthenticatedWeb\QuoteSummary.aspx.cs 1293 26 C:\...\AuthenticatedWeb\

flagging the .Enable property. I'm probabaly overlooking something but I'm
not sure what.

regards!
Bill
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top