Hello CipherIS,
For Each ctrl As Object In Parent.Controls
Because you cannot guarantee that everything can be coerced to a control it is safe to use object though as this can accept any type.
Regards,
TimCottee
Main Topics
Browse All TopicsI have a webpage that is utilizing a Master Page.
I am utilizing the following code below. I want to set the check box values = False. I am receiving the following error dispalyed in the JPG.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I am using a Master Page - index.master. I have code on another page employee.aspx. In employment.aspx.vb I need to write code that will find the check boxes on the employee.aspx code. Each code sample that I use above looks at the Master page. I need to find the control (check boxes) on the employee.aspx form.
It looks like you are trying to find controls on an UpdatePanel. Unfortunately, the UpdatePanel has a sub-container that confuses the issue. You need to use FindControl from that sub-container to get any references to controls, or use a recursive find method that starts at the UpdatePanel, and works down to all the children recursively.
You have to look at the entire control hierarchy, which is a tree structure. If you are looking at top-level controls, you won't find anything. Another short cut is to find the naming container that the controls are on, and use FindControl from that container to get a reference to the control that you need.
1) Get a reference to the UpdatePanel:
Dim updatePanel1 As UpdatePanel = TryCast(Page.Form.FindCont
2) Loop through the controls for the UpdatePanel:
If updatePanel1 IsNot Nothing Then
For Each ctl As Control In updatePanel.Controls
If TypeOf ctl is CheckBox Then
Dim chk As CheckBox = CType(ctl, CheckBox)
End If
Next ctl
End If
Ok, you are using a MasterPage, so the UpdatePanel is not on the page directly, it is contained by the ContentPlaceHolder. When the page is rendered, look at the unique ID (View source in Browser), and it will be something like ctl00$ContentPlaceHolder1$
Business Accounts
Answer for Membership
by: CipherISPosted on 2008-08-21 at 07:04:22ID: 22279626
When I use "Me.Controls" or "Page.Controls" I receive the following error: Unable to cast object of type 'ASP.index_master' to type 'System.Windows.Forms.Cont rol'.