Re: Looping through textboxes - error in my code?

From: Tee (thy_at_streamyx.com)
Date: 07/01/04


Date: Fri, 2 Jul 2004 02:36:37 +0800

I think I knew what you need.
I was having the same problem last time, for each control loop work in
windows form but not web form. In web forms, you need to use a recursive
function to search thru all the levels. I'm not very sure how to explain it,
I will post a code that hope can help you here.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

EnableTextboxes(Controls)

End Sub

Private Sub EnableTextboxes(ByVal col As ControlCollection)

If (col Is Nothing) Then

Return

End If

Dim c As Control

For Each c In col

If TypeOf c Is TextBox Then

CType(c, TextBox).Enabled = True

End If

ChangeTextboxes(c.Controls)

Next

End Sub

With this recursive function, it will search thru all levels of object, eg:
the texbox is inside a panel, a panel is inside a form
if you don't use recursive function, you only get those textboxes in the
form but not the panel.

HTH,
Tee

"Nick" <Nick@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:egrCis4XEHA.1152@TK2MSFTNGP09.phx.gbl...
> Hi - I tried changing the code - but same result. Code runs fine with no
> errors, but doesn't enable the textboxes.
> Does the postback change them back to enabled=false as that is the default
> setting in the IDE??
>
> Nick
>
> "Crosta" <Crosta@Crosta.Crosta> wrote in message
> news:whs2vuwk073s.50803p8cbilc$.dlg@40tude.net...
> > In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
> >
> >
> > Why instead of this:
> >
> > Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl
> > textbox.Enabled = True
> >
> > you don't use this:
> >
> > DirectCast(frmCtrl, System.Web.UI.WebControls.TextBox).Enabled = True
> >
> > ?
>
>


Loading