Two question about Master Page

  • Thread starter Thread starter lichaoir
  • Start date Start date
L

lichaoir

I have two questions about the use of Master Page:

1. How to access properties and controls in the master page from
content page? (I know I can use the "FindControl()" method of the
"Master" Property to access the controls. But how can I access the
properties? I've tried to write a property in the master page and
access it from content page, but it didn't work.)

2. How to specify default content in the master page? (I've tried to
write something directly in the "ContentPlaceHolder" of the master
page. But I can't see it through running the content page, why?)

Thanks for your answer and discussion!
 
1. How to access properties and controls in the master page from
content page?

To access properties you use the Page.Master property. Page.Master returns
the Master Page as a MasterPage object. To access the members of your
inherited MasterPage you need to cast it to the proper type. You can do so
by adding a MasterType directive to the top of your content page.

2. How to specify default content in the master page? (I've tried to
write something directly in the "ContentPlaceHolder" of the master
page. But I can't see it through running the content page, why?)

By default Content Pages automatically define custom content for the
Content sections. If you want it to use the default content then you can
right-click on the Content Panel and select "Default to Master's Content"
 
Thanks for your answer!
If I put something as the default content in the master page and then
put some other things in the content page, can I see both of the
content?
 
No. The master page has no idea what kind of stuff your going to put in the
Content Pages, thus it has no way to properly merge it with it's default
content. For example you may just put some text while another person may have
nothing except an imbedded flash animation.

However, you can add more than one content place holder on your master page.
Put the default content in one of the place holders and leave the other free
for the Content Page's content.
 
Back
Top