By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,647 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,647 IT Pros & Developers. It's quick & easy.

Iterating Controls on ContentPlaceHolder

P: n/a
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
Mar 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

"Bill44077" <Bi*******@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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

Mar 3 '06 #2

P: n/a
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
"Bruce Barker" wrote:
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)

"Bill44077" <Bi*******@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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


Mar 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.