FindControl Question

T

Teemu Keiski

Just to make sure, is the HTML web control associated with runat="server"
i.e it is server-side control? For example: <input type="hidden"
ID="theHidden" runat="server" />

I am asking because FindControl can only locate controls with runat="server"
i.e server-side controls.
 
A

Andrea Williams

Ok, thanks to a kind person yesterday, I've started using the FindControl()
method. Although I able to get this to work for Web Controls, I'm unable to
find the HTML Controls? Am I missing something still? Do I really have to
use the Web controls in order to be able to change properties on the
control?

I'm trying to create a user control and have the apsx page include that
control, but change a few properties, like the Table Border size, or the
HTMLInputText.Name on a text field. Possible? FindControl() doesn't seem
to work unless it's a Web control... Am I missing something?

Thanks in advance!
Andrea
 
A

Andrea Williams

No they weren't.... I didn't even think of that, but now that you suggest
it, it makes sense. Although when I tried to add it visa the Properties
yesterday, the runat property is greyed out (I guess that's why I thought it
wasn't needed). I typed it manually into the HTML tag, and now I'm able to
find it.

THX! It's much appreciated. And so fast. Thanks again!
Andrea
 
K

Kevin Spencer

Shouldn't be any different. However, be aware that Controls can be nested,
but that the FindControl() method only searches the immediate Controls under
a Control. Example:

Form1
Control1
SubControl1
SubControl2
Control2
SubControl3
SubSubControl1

Using the FindControl() method on Form1, you could find Control1 and
Control2. To find SubControl1, you would have to use the FindControl()
method of Control1. To find SubSubControl1, you would use the FindControl()
method of SubControl3.

If necessary, you can write a recursive function that searches all Controls
of a given Control, and then recursively calls itself for each Control in
that Collection.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top