1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Identifying the masterpage name and content control name programmatically

Identifying the masterpage name and content control name programmatically

4 posts, 0 answered
  1. sarath
    sarath avatar
    24 posts
    Registered:
    24 Jan 2010
    03 Feb 2010
    Link to this post
    I have a Sitefinity template master called parent.master,
    <%@ Master Language="C#" %>
    <%@ Register Namespace="Telerik.Cms.Web" Assembly="Telerik.Cms" TagPrefix="sf1" %>
    <asp:contentplaceholder id="FooterContent" runat="server"></asp:contentplaceholder>

    and I have a nested master page(non CMS) called Child.Master, it hase footer.ascx user control placed with in asp:content control and contentplaceholderid is footercontent.

    <%@ Master Language="C#" AutoEventWireup="true" MasterPageFile="~/Parent.Master" CodeBehind="Child.master.cs" Inherits="NestedMasterPagesApp1.Child" %>
    <%@ Register src="footer.ascx" tagname="footer" tagprefix="uc1" %>
    <asp:Content ID="Content3" runat="server" contentplaceholderID="FooterContent" >
        <uc1:footer ID="footer1" runat="server" />
    </asp:Content>

    how to find programmatically name of the asp:content control contentplaceholderid and the cms masterpage name(i.e parent) to pull the content from the cms master page. I am planning to make this footer.ascx to generic.ascx and I can use the single control to use for different asp:content controls.

    Thanks,
    Sarath

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Feb 2010
    Link to this post
    Hi sarath,

    You can use Page.Master.Master where Page.Master - gets the master page of the current page and Page.Master.Master - gets the parent master page of the current master in nested scenario. Then you can use the page controls collection to find each control you want.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. sarath
    sarath avatar
    24 posts
    Registered:
    24 Jan 2010
    03 Feb 2010
    Link to this post
    Thank you for your quick reply.

    But the problem here is i want to identify the asp:content control controlplaceholderid, for example in the below code same footer.ascx control has been placed with in three different asp:content controls. Here how to identify the contentplaceholderID , the usercontrol is part of it.(i.e footer1 --> TopmenuContent, footer2 -->LeftMenuContent, footer3 --> FooterContent)

    <asp:Content ID="Content3" runat="server" contentplaceholderID="TopMenuContent" >
        <uc1:footer ID="footer1" runat="server" />
    </asp:Content>

    <asp:Content ID="Content3" runat="server" contentplaceholderID="LeftMenuContent" >
        <uc1:footer ID="footer2" runat="server" />
    </asp:Content>
    .....
    ...
    <asp:Content ID="Content3" runat="server" contentplaceholderID="FooterContent" >
        <uc1:footer ID="footer3" runat="server" />
    </asp:Content>
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Feb 2010
    Link to this post
    Hello sarath,

    You cannot have reference to the Control. you need to use FindControl with a reference to the root master page where the ContentPlaceHolder resides.

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:Label runat="server" Text="Hello" ID="MyControl"></asp:Label>
    </asp:Content>

    ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Master.FindControl("head");
    Label lb = contentPlaceHolder.FindControl("MyControl") as Label;


    http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx
    http://odetocode.com/Code/450.aspx
    http://forums.asp.net/t/1059255.aspx

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
4 posts, 0 answered