473,387 Members | 3,787 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,387 software developers and data experts.

Loop through controls with MaterPage ContentHolder

I changed my aspx page to use a master page. The problem is that I can no
longer loop through the controls on the content page. My question is how do
you loop through the controls on the master page and how do you loop through
the controls on the content page when the content is inside the ContentHolder
control?

Below is an example of the control loop before using a master page.

Sub FindControlsInWebForm()
Dim strValue As String = ""

'Loop through controls
For Each ctlPage As Control In Page.Controls
If TypeOf ctlPage Is HtmlForm Then
For Each ctlChild As Control In ctlPage.Controls
If TypeOf ctlChild Is Label Then strValue &= "Page.Label.ID = " &
ctlChild.ID & ".ID<br>"

'Panel
If TypeOf ctlChild Is Panel Then
strValue = "Panel.ID = " & ctlChild.ID & ".ID<br>"

For Each ctlGrndChild As Control In ctlChild.Controls
If TypeOf ctlGrndChild Is TextBox Then strValue &=
"Panel.TextBox.ID = " & ctlGrndChild.ID & ".ID<br>"
Next ctlGrndChild
End If
Next ctlChild
End If
Next ctlPage
End Sub

--
Thanks in advance,
sck10
Nov 18 '05 #1
4 6331
Hi sck10,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 18 '05 #2
Hi sck10:

The hierarchy of controls with MasterPages looks like this:

Page
- MasterPage
- HtmlForm
- ContentPlaceHolder
- The TextBoxes, etc.

So your logic could look something like the following.

For Each ctlMaster As Control In Page.Controls
If TypeOf ctlMaster Is MasterPage Then
For Each ctlForm As Control In ctlMaster.Controls
If TypeOf ctlForm Is HtmlForm Then
For Each ctlContent As Control In ctlForm.Controls
If TypeOf ctlContent Is ContentPlaceHolder Then
For Each ctlChild As Control In ctlContent.Controls
' Do work...
Next
End If
Next
End If
Next
End If
Next

--
Scott
http://www.OdeToCode.com

On Fri, 24 Sep 2004 09:02:19 -0700, "sck10" <sc***@online.nospam>
wrote:
I changed my aspx page to use a master page. The problem is that I can no
longer loop through the controls on the content page. My question is how do
you loop through the controls on the master page and how do you loop through
the controls on the content page when the content is inside the ContentHolder
control?

Below is an example of the control loop before using a master page.

Sub FindControlsInWebForm()
Dim strValue As String = ""

'Loop through controls
For Each ctlPage As Control In Page.Controls
If TypeOf ctlPage Is HtmlForm Then
For Each ctlChild As Control In ctlPage.Controls
If TypeOf ctlChild Is Label Then strValue &= "Page.Label.ID = " &
ctlChild.ID & ".ID<br>"

'Panel
If TypeOf ctlChild Is Panel Then
strValue = "Panel.ID = " & ctlChild.ID & ".ID<br>"

For Each ctlGrndChild As Control In ctlChild.Controls
If TypeOf ctlGrndChild Is TextBox Then strValue &=
"Panel.TextBox.ID = " & ctlGrndChild.ID & ".ID<br>"
Next ctlGrndChild
End If
Next ctlChild
End If
Next ctlPage
End Sub


Nov 18 '05 #3
Thanks for Scott's informative suggestions.

Hi sck10,

Scott has provide the detailed description on the MasterPage customized
page's control hierarchy and here is another blog article which has also
mentioned this hehavior:

http://dotnetjunkies.com/WebLog/jpal.../01/23919.aspx

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hi Sck10,

Have you had a chance to check the former messages or have you got any
further ideas on this problem. If there are any thing else we can help,
please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5

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

Similar topics

4
by: Ryan Liu | last post by:
How to loop though controls on the form? I set each control's TabStop and TabIndex, but at run time, I press Tab key, it jump though first control to last control and does not go back to the...
4
by: David A. Beck | last post by:
Is there a way I can loop through a form object in ASP.NET codebehind like in VB.NET and get all of the controls?
4
by: Ryan Ternier | last post by:
Thanks for the previous help guys! I got my list box issue working, but now i'm trying to loop through all the items in my page. I want to find each listbox, once I do i strip the ID down to...
0
by: Steven K | last post by:
Hello, I just worked through finding controls on a page with and without a panel. My question is how do you loop through controls if you are using a master page and your content is inside the...
33
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...
3
by: Kezza | last post by:
Hi There.. I have dynamically created some textbox and checkbox controls by adding them to a panel. Now I would like to get the values out. I have created a for each loop that I can see the...
8
by: dominique | last post by:
Hi, Is it possible (in vb.net with WinForms) to loop throw controls inside a container (form or panel) sorting the controls on a property (.tabindex for example) ? My problem : on several...
4
by: Bart | last post by:
Hi, I have a menu on my master page. When I click on a menu item the state is reset after the page is redirected to the NavigateURL. How can fix this? Thanks Bart
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.