Search through controls in Page

M

^MisterJingo^

Hi all,

I think i'm missing something here.

I have a page with a number of textboxes in it and I simply want to
enable or disable them on a button click. I first search through page:

foreach (Control ctrl in Page.Controls)

and then to check their type I:

Response.Write(ctrl.GetType().ToString() + "<br/>");

Every control is given as type "System.Web.UI.LiteralControl", and so i
cannot cast to WebControl and access the Enabled property. None of the
controls are in panels, so the above should see them?
What am I doing wrong here? Any help would be appreciated;
 
K

Kevin Spencer

Search the Form instead of the Page.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.
 
M

^MisterJingo^

^MisterJingo^ said:
Hi all,

I think i'm missing something here.

I have a page with a number of textboxes in it and I simply want to
enable or disable them on a button click. I first search through page:

foreach (Control ctrl in Page.Controls)

and then to check their type I:

Response.Write(ctrl.GetType().ToString() + "<br/>");

Every control is given as type "System.Web.UI.LiteralControl", and so i
cannot cast to WebControl and access the Enabled property. None of the
controls are in panels, so the above should see them?
What am I doing wrong here? Any help would be appreciated;

I just tried the following and it seemed to work:

foreach(Control ctrl in Page.FindControl("form1").Controls)
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top