473,721 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem iterating through controls on a web form.

hi there,

i have a strange problem. I want to programatically loop through each
control on a page, but am having issues.

my test example:

1. header.ascx - the ascx control finds all the child controls no problems

2. default.aspx - i dont find any controls that are placed directly on the
form.

i call the function as follows

AddControlsToDa tabase(Me) - this is placed on every page_ for both ASPX
pages and ASCX pages.
my function is as follows:
Sub AddControlsToDa tabase(ByVal mypage As Object)
For Each c As Control In mypage.controls
'hyperlink
If TypeOf c Is HyperLink Then
Dim l As HyperLink = CType(c, HyperLink)
'...my code goes here...
End If
'Button
If TypeOf c Is Button Then
Dim l As Button = CType(c, Button)
'...my code goes here...
End If
Next
End Sub

Any help is appreciated in why this doesnt pickup the ASPX page controls
within the Controls collection.

thanks,

Paul.
Nov 18 '05 #1
4 1682
For Each Control In Me.Controls

Next
"Milsnips" <mi******@hotma il.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
hi there,

i have a strange problem. I want to programatically loop through each
control on a page, but am having issues.

my test example:

1. header.ascx - the ascx control finds all the child controls no
problems

2. default.aspx - i dont find any controls that are placed directly on
the
form.

i call the function as follows

AddControlsToDa tabase(Me) - this is placed on every page_ for both ASPX
pages and ASCX pages.
my function is as follows:
Sub AddControlsToDa tabase(ByVal mypage As Object)
For Each c As Control In mypage.controls
'hyperlink
If TypeOf c Is HyperLink Then
Dim l As HyperLink = CType(c, HyperLink)
'...my code goes here...
End If
'Button
If TypeOf c Is Button Then
Dim l As Button = CType(c, Button)
'...my code goes here...
End If
Next
End Sub

Any help is appreciated in why this doesnt pickup the ASPX page controls
within the Controls collection.

thanks,

Paul.

Nov 18 '05 #2
thanks.. problem solved.

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OE******** *****@TK2MSFTNG P10.phx.gbl...
For Each Control In Me.Controls

Next
"Milsnips" <mi******@hotma il.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
hi there,

i have a strange problem. I want to programatically loop through each
control on a page, but am having issues.

my test example:

1. header.ascx - the ascx control finds all the child controls no
problems

2. default.aspx - i dont find any controls that are placed directly on
the
form.

i call the function as follows

AddControlsToDa tabase(Me) - this is placed on every page_ for both ASPX
pages and ASCX pages.
my function is as follows:
Sub AddControlsToDa tabase(ByVal mypage As Object)
For Each c As Control In mypage.controls
'hyperlink
If TypeOf c Is HyperLink Then
Dim l As HyperLink = CType(c, HyperLink)
'...my code goes here...
End If
'Button
If TypeOf c Is Button Then
Dim l As Button = CType(c, Button)
'...my code goes here...
End If
Next
End Sub

Any help is appreciated in why this doesnt pickup the ASPX page controls
within the Controls collection.

thanks,

Paul.


Nov 18 '05 #3
For .aspx pages, the controls are placed inside the form (<form> tag), not
at the page level itself. So, you have to loop through the Controls
collection of the form control instance.

Dim f As HtmlForm = Me.FindControl (<form tag id>)
For Each c As Control in f.Controls
....
If TypeOf c Is Button Then
End If
....
Next

As discussed earlier in the group, you may have to use recursion to
loop-through controls inside a container control which could be a member of
a Controls collection.

HTH

"Milsnips" <mi******@hotma il.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
hi there,

i have a strange problem. I want to programatically loop through each
control on a page, but am having issues.

my test example:

1. header.ascx - the ascx control finds all the child controls no problems

2. default.aspx - i dont find any controls that are placed directly on the
form.

i call the function as follows

AddControlsToDa tabase(Me) - this is placed on every page_ for both ASPX
pages and ASCX pages.
my function is as follows:
Sub AddControlsToDa tabase(ByVal mypage As Object)
For Each c As Control In mypage.controls
'hyperlink
If TypeOf c Is HyperLink Then
Dim l As HyperLink = CType(c, HyperLink)
'...my code goes here...
End If
'Button
If TypeOf c Is Button Then
Dim l As Button = CType(c, Button)
'...my code goes here...
End If
Next
End Sub

Any help is appreciated in why this doesnt pickup the ASPX page controls
within the Controls collection.

thanks,

Paul.

Nov 18 '05 #4
Your welcome...Good luck!

"Milsnips" <mi******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
thanks.. problem solved.

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OE******** *****@TK2MSFTNG P10.phx.gbl...
For Each Control In Me.Controls

Next
"Milsnips" <mi******@hotma il.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
> hi there,
>
> i have a strange problem. I want to programatically loop through each
> control on a page, but am having issues.
>
> my test example:
>
> 1. header.ascx - the ascx control finds all the child controls no
> problems
>
> 2. default.aspx - i dont find any controls that are placed directly
> on
> the
> form.
>
> i call the function as follows
>
> AddControlsToDa tabase(Me) - this is placed on every page_ for both
> ASPX
> pages and ASCX pages.
>
>
> my function is as follows:
> Sub AddControlsToDa tabase(ByVal mypage As Object)
> For Each c As Control In mypage.controls
> 'hyperlink
> If TypeOf c Is HyperLink Then
> Dim l As HyperLink = CType(c, HyperLink)
> '...my code goes here...
> End If
>
>
> 'Button
> If TypeOf c Is Button Then
> Dim l As Button = CType(c, Button)
> '...my code goes here...
> End If
> Next
> End Sub
>
>
>
> Any help is appreciated in why this doesnt pickup the ASPX page
> controls
> within the Controls collection.
>
> thanks,
>
> Paul.
>
>



Nov 18 '05 #5

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

Similar topics

4
23819
by: Adam Parkin | last post by:
Hi all, what I want to do is write a function to toggle the enabled field of all controls within a frame, but what I can't figure out is how does one iterate through all controls in a frame object? For example, if I wanted to iterate through all controls in a form, I'd write something like: Dim x For Each x In frmMyForm.Controls x.Enabled = Not x.Enabled
1
3214
by: Jeremy | last post by:
I have been trying to iterate through the controls on my form and preset all textboxes to a cssClass. Unfortunately, I have been unable to figure out how to recursively move through sub-controls and all of my textboxes are in asp panels. The code I have can see the panels but not what is in them. Help please. Current code:
6
1293
by: Dany P. Wu | last post by:
Hi everyone, I created a page which contains a two-column table. The first column has a bunch of labels, and the second a bunch of textboxes. Here's the code: ====================================================== Protected WithEvents Container As System.Web.UI.WebControls.PlaceHolder Private Sub ConstructEditTable() Container.Controls.Add(New LiteralControl("<table>" & vbNewLine))
4
1693
by: John Buchmann | last post by:
I thought this would not be difficult, but i'm stumped! I need to iterate through a bunch of form fields, and read the data (value, text, etc.) from them. (I need to iterate through them programmatically because it is not known ahead of time which form fields will be displayed on the browser. The fields will be displayed or hidden depending on what the user just clicked.)
4
4426
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing End If If TypeOf c Is DropDownList Then CType(c, DropDownList).SelectedIndex = 0 End If Next
3
3258
by: J'son | last post by:
Guys, I have created a custom class that derives from DataList so that I can add some custom client side functionality into each new item row (<td>). Heres the class in its simplest form: public class MyDataList : DataList { public string MyValue1 = "alert('Hey there!');"; public string MyValue2 = "alert('Hey there yourself!');";
7
2224
by: ThunderMusic | last post by:
Hi, I have a CheckBoxList and I want to add some javascript code to each CheckBox created by this CheckBoxList. I tried iterating through all items of the list, all the controls, do a FindControl, et al. with no good result. I would use the Control.Attribute.Add("OnClick", "some javascript code") Does someone know a solution? Thanks
3
1877
by: Varangian | last post by:
Hello how come foreach(ImageButton imgbtn in Page.Controls) doesn't work ? whats wrong in that statement? what should I do? I need to go through each ImageButton in the Page, without going through all the other controls. thanks
2
5048
by: David Veeneman | last post by:
Is there a way to iterate the components on a form? I need to determine whether an instance of my custom component (a System.ComponentModel component) is present in a form. I have tried iterating the Controls collection, but components do not appear to be in that collection-- I think it's because components inherit from MarshalByRefObject, rather than Control. So, how do I find a form's components collection? Thanks in advance.
0
9215
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
9131
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
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
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
4484
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
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
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.