Loop Through Textboxes

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
 
R

RCra69

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
 
J

Jason

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/
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top