469,613 Members | 1,315 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Two question about Master Page

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!

Oct 31 '07 #1
4 1363
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.

<%@ MasterType virtualpath="~/Main.master" %>
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"

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"lichaoir" <li******@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
>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!
Oct 31 '07 #2
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?

Oct 31 '07 #3
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.

--
Andrew Faust
http://www.andrewfaust.com
"lichaoir" wrote:
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?

Oct 31 '07 #4
Thanks a lot!

Nov 1 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Michael Herman \(Parallelspace\) | last post: by
4 posts views Thread by Steve Franks | last post: by
17 posts views Thread by Rob R. Ainscough | last post: by
6 posts views Thread by Sam Carleton | last post: by
7 posts views Thread by Just Me | last post: by
6 posts views Thread by =?Utf-8?B?SmF5IFBvbmR5?= | last post: by
10 posts views Thread by =?Utf-8?B?RGFuaQ==?= | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.