What is the best approach to populate a master page control that depends on the content page?

I have a master page named SampleMaster.master and this page contains a Repeater control

The Repeater element will be used to display the appropriate tags associated with each content page and the tags will be different between content pages

The Tags.GetTags () data retrieval method works, but I don't know how best to use the Repeater element in the master page depending on which content page is.

Will the code be in the master page code or the content page code?

+2


source to share


3 answers


I suggest exposing a property or method on the child page that passes the master page to the displayed tags. for example

partial class myPage : IMyTaggablePage
{
    // the following is an interface member
    public List<string> GetTags()
    {
        return this.Taglist; // assuming taglist was populated somewhere on this page.
    }
}

      



Then on the homepage, you can write something like:

if (this.Page is IMyTaggablePage)
    var tags = (Page as IMyTaggablePage).GetTags();

      

+5


source


You can put it on the home page if you can. Ideally, your content page should not know the parent and should assume that it can be used anywhere.



This will result in more detailed, reusable designs for your content pages.

0


source


You can expose the functionality of your master page through your content page by adding the following aspx files to your content pages:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

      

Then, from the content page, you will be able to access any of the ways that you opened on the main page.

So you will have a method like this on your homepage:

public void BuildMyCustomStuff(YouInputType in)
{
    // Do something with the data passed in
}

      

Then, in the content page, you call the function with:

Master.BuildMyCustomStuff(dataIn);

      

0


source







All Articles