Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2007, 08:52 AM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default loop through controls and master page

Hello!

I have a master page

In a .aspx file I am calling the master page

I create a sub to loop through controls and clean all textbox

Public Sub CleanControls(ByVal oControl As Control)

        Dim o_Control As Control
        For Each o_Control In oControl.Controls

            If o_Control.GetType().ToString().Equals("System.Web. UI.WebControls.TextBox") Then
                CType(o_Control, TextBox).Text = ""
            End If
        Next
    End Sub



The problem is when I send the collection, It send the master page and not the content page and o_Control.GetType().ToString() return ASP.MasterPageName and not System.Web.UI.WebControls.TextBox.

I don't know how to send the control collection

Thanks..
 
Old June 19th, 2007, 09:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The page (whether or not it uses a master page) contains a single controls collection. It is really a control tree that you need to recurse into. You can not just loop thru one level of a collection. As an example, if you have an asp:panel on a page with a text box in it, the page's control collection will contain the panel and the panel's controls collection will contain the textbox.

Write a recursive method that accepts a control collection so that you can loop thru a single collection but recurse as needed.

<advanced suggestion>
Make the method take a delegate with Control as its single argument and you'll have a method that you can use for many things. Call delegate for each control you process and pass the control to the delegate. Then in the callback method you simply need to test the control for the type you wish to act upon and do what you want.
</advanced suggestion>

-Peter
 
Old June 19th, 2007, 01:25 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the answer by myself

I used
-------------------------------------------------
Dim cphContentPlaceHolder As ContentPlaceHolder
cphContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolderName") , ContentPlaceHolder)

--------------------------------------------

Passed mpContentPlaceHolder to the sub and ready..that its





Similar Threads
Thread Thread Starter Forum Replies Last Post
Master Page Method: Code-Behind for Content Page kwilliams ASP.NET 2.0 Professional 3 June 2nd, 2008 12:57 PM
Master Page and Content Page with Java script Harjinder ASP.NET 2.0 Professional 1 February 1st, 2008 10:31 AM
Using Controls within a For...Next loop FalseParadigm Access VBA 3 December 20th, 2006 10:01 AM
How to get inner repeater controls in master detai ceema .NET Framework 2.0 0 September 7th, 2005 01:42 AM
Loop thru controls Mitch Access 2 December 23rd, 2003 02:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.