access placeholder in page.aspx page from an uc.ascx, using masterpage on my aspx page

Posted on 2006-05-14
Last Modified: 2011-08-18
Hi experts! I am having some problems here since i changed to masterpage! The problem is that before i had masterpage the code below(code from uc.ascx) was valid as it found the "Form1" which was on the page.aspx, but since i changed to masterpage it doesnot find my form or anything on my page.aspx....

i have tried with Findcontrol but it doesnot work as easily as i hoped...

-----code in page.aspx
<asp:Content ID="mc1" ContentPlaceHolderID="mc" runat="Server">
   <div style="margin: auto;">
<table id="TableTitle" cellspacing="0" cellpadding="0" width="100%" border="0">
            <td class="TabHeading">
               &nbsp;<asp:Label ID="lblTitle" runat="server" CssClass="Label"></asp:Label>&nbsp;<asp:PlaceHolder
                  ID="plcObjectInfo" runat="server"></asp:PlaceHolder>
               <asp:PlaceHolder ID="plcPages" runat="server"></asp:PlaceHolder>
               <asp:PlaceHolder ID="plcNavigate" runat="server"></asp:PlaceHolder>
               <asp:Button ID="btnUpdate" runat="server" Width="100px" Text="Button"></asp:Button>&nbsp;&nbsp;</td>

--------code in uc.ascx.vb
For Each oControl As Object In Page.FindControl("Form1").Controls
            If TypeOf oControl Is PlaceHolder Then
               Select Case DirectCast(oControl, PlaceHolder).ID.ToLower()
                  Case "plcobjectinfo"
                  Case "plcnavigate"
                  Case "plcpages"
               End Select
            End If

i have tried to reference to page.aspx this way, instead of "Form1" i tried to find my contentplaceholder and then find the table that is in it....
'' Gets a referencees to masterpages controls
         Dim mpContentPlaceHolder As ContentPlaceHolder
         Dim myTableTitle As Table

         mpContentPlaceHolder = CType(Page.Master.FindControl("mc"), ContentPlaceHolder)<-------------this row work and finds the contenetplaceholder "mc"
         myTableTitle = CType(mpContentPlaceHolder.FindControl("TableTitle"), Table)<--------------thins one doesnt find anything

I have used this same code to access other controls on other pages and it worked fine, but here in uc.ascx it only finds the contensplaceholdern and not what is inside it? Do i run this code to early, in that case when and how should i run it??
Question by:adismesevic
    1 Comment
    LVL 27

    Accepted Solution

    I dont think you can do that simply because the findcontrol method only finds the controls contained within a container not its child controls.
    is there a postback involved in here? are you recreating the usercontrol up on postback?

    take a look at this post, it may help

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now