ASP.NET Nested master pages, how to set content on top page from aspx file?

I have content from a CMS that I need to move to raw asp.net pages. Since the templates are nested, I think I can use nested master pages to get my head around it, but I found that I cannot set values ​​on the master master page from a deep child page.

Here's an example. I have several nested master pages with content sites:

  • top master (with contentPlaceHolder1)
  • nested master dependent on master master (with contentPlaceHolder2)
  • aspx page dependent on nested master defines content for contentPlaceHolder1 and 2

The problem is that asp.net does not allow me to have the contentPlaceHolder1 value defined in the content page, it must be defined in the nested master. But the point is, the client page knows this value, not the template wizards (for example, the page knows about the graphic it should display on top, but the plot placeholder is the master wizard).

How can I set the values ​​on the aspx page to be displayed in the top main file?

+2


a source to share


2 answers


Usually you will need to do the following:

  • set up public property on the homepage
  • add the @MasterPage declaration to the beginning of any content page you want to access the property in
  • access type property Master.YourPageProperty = "value";

In the case of nested master pages, you must also configure the public pass-through properties using the same method above, but do so in your nested master page (i.e. define the master page of the nested master pages and set up dummy public properties that simply set the value passed to the nested master in the upper master).



Try taking a look at this article to reinforce the ideas I touched on:

+1


a source


I usually make all my .aspx pages inherit from the base page, and on this page, I set up properties for any data I want to share. Then on the master page of the master page, you can overlay the current page with the base page type and then access all the data.



I usually expose the base page as a property on my master page, this way I can do a soft listing and do a null check if I have a case where a page that does not inherit from my base page uses the master page.

0


a source







All Articles