Loop Through Textboxes

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I want to loop through all textbox controls to determine
their .text value. If the .text value is not "" then
display the textbox.

I have tried the following with no luck. Any help would
be appreciated.

Dim ctrl as Control
For Each ctrl in Page.Controls
If ctrl.GetType.ToString
= "System.Web.UI.WebControls.TextBox" Then
ctrl.Attributes.Add("style", "DISPLAY: ")
End If
Next
 
Your code is running server side so you may as well take advantage of server control properties rather than worrying about client-side attributes as you have done. See also I have changed the type comparison

Dim ctrl as Contro
For Each ctrl in Page.Control
If ctrl.GetType Is GetType(System.Web.UI.WebControls.TextBox) The
ctrl.Visible = Tru
End I
Nex

hth, ro
 
That didn't work. Here is an example of one of my
textboxes:

<asp:textbox id="txt1" style="DISPLAY: none"
runat="server" Width="80px"></asp:textbox>

I am using client side javascript to show / hide the text
box based on the selection of a listbox. I am posting
back to the page after entering text in the textbox.
When posting back all of the textboxes are not displayed
because of the style property (display: none).

Basically I want to display all text boxes when there is
text in them after posting to the page. But I also need
them hidden prior to the listbox selection. Hope I
explained correctly.
-----Original Message-----
Your code is running server side so you may as well take
advantage of server control properties rather than
worrying about client-side attributes as you have done.
See also I have changed the type comparison.
Dim ctrl as Control
For Each ctrl in Page.Controls
If ctrl.GetType Is GetType
(System.Web.UI.WebControls.TextBox) Then
ctrl.Visible = True
End If
Next

hth, ro.
from .NET's Largest Community Website:
http://www.dotnetjunkies.com/newsgroups/
 
Back
Top