FindControl Question

  • Thread starter Thread starter Teemu Keiski
  • Start date Start date
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.
 
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
 
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
 
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.
 
Back
Top