473,378 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Loop Through Textboxes

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
Nov 18 '05 #1
2 1466
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
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #2
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.
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website:
http://www.dotnetjunkies.com/newsgroups/.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Fitzgibbon | last post by:
Stupid question: How do I loop through many text boxes on a page and get values for each box and put into an array? For example document.CreateEvent.test1.value will not take an array value...
4
by: Kevin H | last post by:
Apologies in advance if this sounds slow-witted, but I didn't find it here. Need to populate some textboxes on a form. While I could hard code it (the number of options aren't that high), it...
4
by: VB Programmer | last post by:
How can I loop thru all textboxes on a form? I want to remove any single quotes in the data entry. I was thinking something like this: For Each c As Control In Me.Controls Dim t As TextBox =...
6
by: Paul D. Fox | last post by:
I want to be able to loop through all the TextBoxes on a page and clear their values. How can I write a function to do that?
2
by: Steve | last post by:
One of the columns in my gridview is a blank textbox (I have added it as a template field). Users can enter a number in the textbox for a multiple of the gridview records. I have a submit button...
6
by: kberry | last post by:
I am clearing Textboxes on a form... this is loop I have came up with but was wondering if it can be shorter or not as long... Can anyone help? Dim controlOnForm As Control 'Places a control...
1
by: Kevin | last post by:
ASP.NET 2.0 I have code that updates a database from a number of textboxes on a web form. I've had to hard coded references to my web form textboxes. I'd like to know how I can reference them...
7
by: Sriku | last post by:
I have created ten textboxes and name them as "txt1,txt2,..txt10" (i.e just changing suffix by consecutive number). Now I have to validate these ten textboxes on Submit event (Say..No textbox...
3
by: =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?= | last post by:
I actually need to do the below for 10 controls ddlInsuranceCompany1.SelectedItem.Text = Value; txtPolicy1.Text = value; SO i opted for a for loop My question is how do i add contol +...
3
by: Shawn | last post by:
I'm trying to go through a large number of logically named textboxes using a loop and cannot figure out how short of explicitly referencing every single one.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.