473,804 Members | 3,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HowTo loop through HTML Table WebControls?

Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:labe l id="lblText" runat="server"> </asp:label>
<asp:button id="btn1" runat="server"> </asp:button>
<asp:button id="btn2" runat="server"> </asp:button>
<asp:button id="btn3" runat="server"> </asp:button>
</td>
</tr>
</table>
Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Cont rols
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Cont rols
there is only 1 Control. Why is this wrong and what is the correct way?

Thanks in advance,
Andreas
Nov 17 '05 #1
3 4308
"Andreas Klemt" <ak******@hotma il.com> wrote in message
news:up******** ******@TK2MSFTN GP12.phx.gbl...
Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:labe l id="lblText" runat="server"> </asp:label>
<asp:button id="btn1" runat="server"> </asp:button>
<asp:button id="btn2" runat="server"> </asp:button>
<asp:button id="btn3" runat="server"> </asp:button>
</td>
</tr>
</table>
Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Cont rols
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Cont rols
there is only 1 Control. Why is this wrong and what is the correct way?


Andreas,

If you looked, you'd see what the type of the one control is. That will tell
you what's going on.
--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com
Nov 17 '05 #2
Hello John,
and why does this not work?

For Each ctl As Control In Me.Controls ?

Thanks,
Andreas
"John Saunders" <jo***********@ surfcontrol.com > schrieb im Newsbeitrag
news:u7******** *****@TK2MSFTNG P10.phx.gbl...
"Andreas Klemt" <ak******@hotma il.com> wrote in message
news:up******** ******@TK2MSFTN GP12.phx.gbl...
Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:labe l id="lblText" runat="server"> </asp:label>
<asp:button id="btn1" runat="server"> </asp:button>
<asp:button id="btn2" runat="server"> </asp:button>
<asp:button id="btn3" runat="server"> </asp:button>
</td>
</tr>
</table>
Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Cont rols
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Cont rols
there is only 1 Control. Why is this wrong and what is the correct way?
Andreas,

If you looked, you'd see what the type of the one control is. That will

tell you what's going on.
--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com

Nov 17 '05 #3
It would be better to keep a question to one newsgroup. Here's the answer I
posted in the other group:

Don't forget that your buttons are inside a table which has its own controls,
so you have to dig a little deeper before you start looping for the buttons.
You might want to use FindControl to get closer to the action.

It helps to turn tracing on in a page to see where controls are really nested.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim ctl As Control
Dim btn As System.Web.UI.W ebControls.Butt on
For Each ctl In myTable.Control s(0).Controls(0 ).Controls
If TypeOf ctl Is System.Web.UI.W ebControls.Butt on Then
btn = ctl
btn.Enabled = False
End If
Next
End Sub

Does this help>

Ken MVP [ASP.NET]
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp

"Andreas Klemt" <ak******@hotma il.com> wrote in message
news:up******** ******@TK2MSFTN GP12.phx.gbl...
Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:labe l id="lblText" runat="server"> </asp:label>
<asp:button id="btn1" runat="server"> </asp:button>
<asp:button id="btn2" runat="server"> </asp:button>
<asp:button id="btn3" runat="server"> </asp:button>
</td>
</tr>
</table>
Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Cont rols
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Cont rols
there is only 1 Control. Why is this wrong and what is the correct way?

Thanks in advance,
Andreas

Nov 17 '05 #4

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

Similar topics

6
2872
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and loop through all the forms in a database and pull information about the form (controls and properties). We would need to do the same in our VB.NET project; loop through the project and get the web form's control and property information...
2
5360
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown reason, this loop iterates only 3 times! Help please! Thanks! Dim Control As Web.UI.Control Dim TextBox As System.Web.UI.WebControls.TextBox For Each Control In Controls If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
2
1428
by: Phil | last post by:
I have an aspx page that contains 5 tables. Each table I have Named tblSection1, tblSection2, tblSection3, tblSection4, tblSection5 respectively and reside in a corresponding panel for collapse and placement purposes. I have a loop in the code behind that will add rows and cells for each table based on what is needed for that particular table. What I need to do is be able to add a row to my table based on the pass of the loop I am in....
1
1524
by: Patrick | last post by:
Problem I have an ASPX file, with a table of 3 columns, 2 rows with a usercontrol in the middle column (in the code snippet stated below, although in reality, the left hand column would also have a user control). I have a "footer" on the second/bottom row. However, when the User Control in the middle column, first row is generating a lot of text, the text is "squashing" the text in the second role!
33
3665
by: Brian | last post by:
I have a list of plain HTML radio buttons that I want to be able to loop through, get the values from them and insert them into a db. each one should be a separate record... Can anyone please give me some kind of example on how to do this???? I am doing this in asp.net VB. Please let me know if you need any additional information. Thanks
4
1269
by: DEWright_CA | last post by:
Hi Everyone! I am working on a project in C# and have a table the contains state info, plus a variety of other info that I will reference from another dropdown list. How can I do this programatically? What I am doing is this, 1. create dbconn, to tblStates (already done!) 2. User has a dropdown list of states, when they select the state the box next to it with Counties displays only the ones for that state, and on
5
3598
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 that for server control component , code is running on the server side. But if I take as example a Label. I place on a webform an HTM label control and a WebForm label control, I could see that properties are different for
0
1510
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
3
1666
by: Guillaume Hanique | last post by:
Hi, I feel very stupid. I simply want to derive a control from system.web.ui.webcontrols.button and use that on my webform, but I just can't get it done. Can anyone tell me how to do that? I can create my own usercontrol (Menu: Website Add new item... Web User Control). This creates an aspx and an aspx.vb file in the root folder, which inherits nicely from system.web.ui.usercontrol. But I want to inherit...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.