473,385 Members | 1,806 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,385 software developers and data experts.

Control eunumeration

Hi,
I need to check whether at least ONE control has been filled in prior to the
user hitting a seacrh button. I have a series of textboxes and a couple of
drop-down list boxes. I've seen in MS Access (yes I know old skool) where
you can do a loop around the different types of controls by their controlid
and check whether they are blank or not. Is there a similar sort of thing
for .net.

Any hints, most welcomed.

Jun 27 '08 #1
3 840
On 2 Giu, 21:09, "axapta" <jas.jac...@gmail.comwrote:
Hi,
I need to check whether at least ONE control has been filled in prior to the
user hitting a seacrh button. *I have a series of textboxes and a coupleof
drop-down list boxes. *I've seen in MS Access (yes I know old skool) where
you can do a loop around the different types of controls by their controlid
and check whether they are blank or not. *Is there a similar sort of thing
for .net.

Any hints, most welcomed.

You can loop on controls, forms or whatever. For instance:

For Each c As Control In Me.Controls

If TypeOf c Is TextBox Then
' ...
End If

Next c
Depending on the case, you may also need recursion.
Tommaso

Jun 27 '08 #2
Tommaso is correct but note that if a textbox is inside a container (e.g.
inside a GroupBox, Panel, TabControl etc) then it won't show up - you need
to go through each container on the form.

(This is what I think Tommaso meant when he mentioned recursion).

--
David Streeter
Synchrotech Software
Sydney Australia
"to**************@uniroma1.it" wrote:
On 2 Giu, 21:09, "axapta" <jas.jac...@gmail.comwrote:
Hi,
I need to check whether at least ONE control has been filled in prior to the
user hitting a seacrh button. I have a series of textboxes and a couple of
drop-down list boxes. I've seen in MS Access (yes I know old skool) where
you can do a loop around the different types of controls by their controlid
and check whether they are blank or not. Is there a similar sort of thing
for .net.

Any hints, most welcomed.


You can loop on controls, forms or whatever. For instance:

For Each c As Control In Me.Controls

If TypeOf c Is TextBox Then
' ...
End If

Next c
Depending on the case, you may also need recursion.
Tommaso

Jun 27 '08 #3
axapta wrote:
I need to check whether at least ONE control has been filled in prior to
the user hitting a seacrh button. I have a series of textboxes and a
couple of drop-down list boxes. I've seen in MS Access (yes I know old
skool) where you can do a loop around the different types of controls by
their controlid and check whether they are blank or not. Is there a
similar sort of thing for .net.
Control Arrays.

Yes, I really did mean to say that.

Use an Array (or similar "list" construct) containing the Controls, in
which you're interested, something like:

Private m_EditControls as Control() = {}

Sub Form_Load( ... ) Handles MyBase.Load

' Put all the controls you care about into the array
m_EditControls = New Control() = _
{ Me.TextBox1 _
, Me.TextBox2 _
, Me.Combobox3 _
}
End Sub

Then, at any point thereafter, you can test for any one of them being
non-blank using something like :

Function AnyValueEntered() as Boolean
For Each ctl as Control in m_EditControls
If ctl.Text <String.Empty Then
Return True
End If
Return False
Next
End Function

If you move into other controls where you have to check more than just
the Text, you'll have to start down-casting to the correct type to get
the right properties, as in:

For Each ctl as Control in m_EditControls
if Typeof ctl Is TextBox Then
if ( DirectCast( ctl, TextBox ).Text <String.Empty Then
Return True
End If
End If

HTH,
Phill W.
Jun 27 '08 #4

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

Similar topics

6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
4
by: gsb58 | last post by:
Hi! On a form I have a calendar. The form is rezised to 1024x768 (Don't worry - this is a training case) when loaded. Now I want to center the calendar on the form so that its edges are...
5
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
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:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.