woensdag 13 mei 2009

Master Page and Content Page Interaction.

When programming asp.net web applications with master and content pages, I often need to access some controls on the master page from the content pages. And it is always a reinvention of the wheel on how to do it the right way.

I have been using the same method for some time now, but never gotten to share this knowledge with the public. I believe the information is unknown to most developers.

Yesterday I came across an article on CodeProject, which describes this method in a very clear way. There goes my article.

The details are in short:

  • Add
    <%@ MasterType virtualpath="~/DetailsMaster.master" %>

    to the content page.




  • Create a public function in the master page to access the control

    public Label LabelReference()

    {
    ' Create a reference to an actual label on the page
    LabelReference = lblDetailsItemName;

    }



  • Call the function from the content page



    Master.LabelReference.Text = "Some Text";






The full details of the aricle are here: CodeProject: Master Page and Content Page Interaction.

1 opmerking:

Thomas zei

Or you can just use;

Master.FindControl("controlName").text = "hello"