Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

nested master pages / access to parent elements from within nested pages' classes

Back to Forum: Tech Off
  • User profile image
    RussianCross

    I am new to .NET / nested master pages. It's my 5th day of researching it, 2.0. So I got the question to you.

    Let's say the root master page (common.master) has the following element:

    <asp:ContentPlaceHolder runat="server" ID="holder_statusbar">
    <div id="statusbar">
    <asp:Label runat="server" ID="lblStatus" Text="Status: " Visible="false" />
    </div>
    </asp:ContentPlaceHolder>

    common.master.cs has something like:
    public partial class common : System.Web.UI.MasterPage
    {
       ...
    }

    I also have a few nested master pages (child1.master, ..., childN.master). Their respected classes derive from class "common".
    I do something like:
    public partial class childN: common
    {
       ...
    }

    So the question is.. How to change the content of lblStatus from within the childN.master.cs? I just would like to have the functionality responsible for changing the text of the statusbar centralized.

    The model is like that: when childN.aspx is called it's retrieving childN.master.cs together with childN.master which deriving from common.master+common.master.cs. May be I am wrong with my architecture. If so I would appreciate if you correct me.

    Thank you very much in advance.

  • User profile image
    Harlequin

    Label MyLabel = base.FindControl("lblStatus") as Label;


    Something like this maybe?

  • User profile image
    RussianCross

    Hi there

    Ok, I've resolved this problem with:

    ContentPlaceHolder holder_statusbar = (ContentPlaceHolder)Master.FindControl("holder_statusbar");
    Label lblStatus = (Label)(holder_statusbar.FindControl("lblStatus"));
    lblStatus.Text = "so hi";

    I don't want to write for all my next content / sub-master pages these 3 lines in each place where I want to call them from...

    So how to put these things into the function, that it would be working from within different sub-pages?

    Thank you very much in advance.


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.