Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

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

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">
         <tr>
            <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>
         </tr>
      </table>

--------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"
                     //code
                  Case "plcnavigate"
                     //code
                  Case "plcpages"
                     //code
               End Select
            End If
         Next

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??
0
adismesevic
Asked:
adismesevic
1 Solution
 
SammyCommented:
adismesevic,
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

http://groups.google.ca/group/microsoft.public.dotnet.framework.aspnet.buildingcontrols/browse_thread/thread/b87a71356d4cc97b/32d682b4ae14c041?lnk=st&q=findcontrol+user+control+viewstate&rnum=6#32d682b4ae14c041
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now