By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Programmatically setting MasterPageFile for an @ Master

P: n/a
I'm looking to discover in what event I can programmatically set this.MasterPageFile for a master page.

Documentation states that this property must be set in the PreInit or before, but master pages don't have a PreInit event -- just an Init event.

So what event is available to a master page that comes before PreInit that can be used to programmatically set the MasterPageFile property?

Thanks in advance!

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Oct 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Perhaps I'm reading this wrong, but wouldn't/couldn't you set this in a page
and inherit it?

For example, if you have a BasePage that all of your other pages inherits.

~/App_Data/BasePage.cs contains:

public class BasePage : Page
{

public BasePage() : base()
{
base.PreInit += new EventHandler(Page_PreInit);
}

protected void Page_PreInit(object sender, EventArgs e)
{

this.MasterPageFile = "~/MasterPage.master";
}

---

~/Default.cs (code-behind for Default.aspx) contains the simple inheritance
of your BasePage:

public partial class _Default : BasePage
{

%code behind code%

}

---

Hope that helps or is what you're looking for. (^_^)

-dl
--
David Longnecker
Web Developer
http://blog.tiredstudent.com
I'm looking to discover in what event I can programmatically set
this.MasterPageFile for a master page.

Documentation states that this property must be set in the PreInit or
before, but master pages don't have a PreInit event -- just an Init
event.

So what event is available to a master page that comes before PreInit
that can be used to programmatically set the MasterPageFile property?

Thanks in advance!

Oct 17 '06 #2

P: n/a
"David R. Longnecker" <dl*********@community.nospamwrote in message
news:a0*************************@msnews.microsoft. com...
Perhaps I'm reading this wrong, but wouldn't/couldn't you set this in a
page and inherit it?
Yep - that's definitely the way to do it...
Oct 17 '06 #3

P: n/a
Thanks, I'll check it this out.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Oct 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.