I'm trying to loop through the 6 server controls I have on my asp page durin
g the Page_Load event. Why don't the controls show up in the Controls colle
ction? I realize that the controls are not rendered at this point, but ther
e must be a way to loop thr
ough them. Here the code I have tried. When I do a count on the controls c
ollection it is 3 even though I have six.
Private Sub Page_Load(...)
Dim oControl as Control
For each oControl in Me.Controls
if oControl.ID = "txtAcct" then
'do some
end if
Next
End Sub
Thanks,
KentYou might want to change your For Each loop to this:
For each oControl in Me.Controls(1).Controls
if oControl.ID = "txtAcct" then
'do some
end if
Next
You also might want to look at the FindControl method.
"Kent" <klkuenzel@.pentaxvision.com> wrote in message
news:FD563FEF-C03E-4FC1-A746-B9E301DF6984@.microsoft.com...
> I'm trying to loop through the 6 server controls I have on my asp page
during the Page_Load event. Why don't the controls show up in the Controls
collection? I realize that the controls are not rendered at this point, but
there must be a way to loop through them. Here the code I have tried. When
I do a count on the controls collection it is 3 even though I have six.
> Private Sub Page_Load(...)
> Dim oControl as Control
> For each oControl in Me.Controls
> if oControl.ID = "txtAcct" then
> 'do some
> end if
> Next
> End Sub
> Thanks,
> Kent
>
>
Are all of your 6 controls direct children of the page? Or only 3 of them
and the other are nested? Controls collection includes only direct children
Eliyahu
"Kent" <klkuenzel@.pentaxvision.com> wrote in message
news:FD563FEF-C03E-4FC1-A746-B9E301DF6984@.microsoft.com...
> I'm trying to loop through the 6 server controls I have on my asp page
during the Page_Load event. Why don't the controls show up in the Controls
collection? I realize that the controls are not rendered at this point, but
there must be a way to loop through them. Here the code I have tried. When
I do a count on the controls collection it is 3 even though I have six.
> Private Sub Page_Load(...)
> Dim oControl as Control
> For each oControl in Me.Controls
> if oControl.ID = "txtAcct" then
> 'do some
> end if
> Next
> End Sub
> Thanks,
> Kent
>
>
Some of the controls might be container for additional controls. Take
a look at http://odetocode.com/Code/71.aspx.
HTH,
Scott
On Thu, 13 May 2004 12:16:04 -0700, "Kent"
<klkuenzel@.pentaxvision.com> wrote:
>I'm trying to loop through the 6 server controls I have on my asp page during the P
age_Load event. Why don't the controls show up in the Controls collection? I reali
ze that the controls are not rendered at this point, but there must be a way to loop
th
rough them. Here the code I have tried. When I do a count on the controls collection it i
s 3 even though I have six.
>Private Sub Page_Load(...)
> Dim oControl as Control
> For each oControl in Me.Controls
> if oControl.ID = "txtAcct" then
> 'do some
> end if
> Next
>End Sub
>Thanks,
>Kent
>
Scott
http://www.OdeToCode.com
Andy,
Thanks your solution worked :
For Each oControl in me.controls(1).controls
'do stuff
next
Also thanks to everyone who responded
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment