<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Master Pages, Themes and Navigation Controls</title><link>http://forums.asp.net/139.aspx</link><description>Discussions of MasterPages, Themes, and other page-related features. &lt;A href="http://aspadvice.com/SignUp/list.aspx?l=164&amp;amp;c=30" target=_blank&gt;Email List&lt;/A&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1839224.aspx</link><pubDate>Fri, 03 Aug 2007 05:59:57 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1839224</guid><dc:creator>Amanda Wang - MSFT</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1839224.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1839224</wfw:commentRss><description>&lt;p&gt;Hi Arjuna,&lt;/p&gt;
&lt;p&gt;You can read this article: &lt;a href="http://weblogs.asp.net/guys/archive/2004/12/05/275321.aspx"&gt;http://weblogs.asp.net/guys/archive/2004/12/05/275321.aspx&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Maybe, it can give you somehelp to solve your problem.&lt;/p&gt;
&lt;p&gt;Please let us know if it works.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1834213.aspx</link><pubDate>Wed, 01 Aug 2007 04:05:11 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1834213</guid><dc:creator>Arjuna_Marambe</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1834213.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1834213</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;&amp;nbsp;Thank you everyone for your replies, but this does not answer my question.&amp;nbsp; &lt;b&gt;I am am changing the MasterPage in the PreInit event &lt;/b&gt;but I still get the ViewState error that I mentioned initially.&amp;nbsp; When I check IsPostback this returns true.&lt;/p&gt;&lt;p&gt;&amp;nbsp;Thanks&lt;/p&gt;&lt;p&gt;Arjuna.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1833279.aspx</link><pubDate>Tue, 31 Jul 2007 17:46:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1833279</guid><dc:creator>Dave Sussman</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1833279.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1833279</wfw:commentRss><description>&lt;p&gt;The problem is, of course, that this only works on a page by page basis, so you&amp;#39;d have to add the PreInit event to every page. A better solution is to hook into a global event in Global.asax, allowing the master to be set dynamically for every page. Here&amp;#39;s what I do:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font face="courier new,courier"&gt; void Application_PreRequestHandlerExecute(object src, EventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // hook up the PreInit page handler&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Page p = this.Context.Handler as Page;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (p != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.PreInit += new EventHandler(page_PreInit);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void page_PreInit(object sender, EventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Page p = this.Context.Handler as Page;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (p != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // set the theme and master page&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Theme = &amp;quot;MyTheme&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.MasterPageFile = &amp;quot;~/MasterPages/MyMaster.master&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;PreRequestHandlerExecute happens early enough in the lifecycle to set the master.&lt;/p&gt;
&lt;p&gt;d&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1833012.aspx</link><pubDate>Tue, 31 Jul 2007 15:53:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1833012</guid><dc:creator>mihirpathak</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1833012.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1833012</wfw:commentRss><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The MasterPage class derives from UserControl. The master page will inject itself as the top&amp;nbsp;control in a page’s control hierarchy by clearing the page’s Controls array and adding itself to into the collection. Doing so includes all of the markup and controls defined inside the master page in the page&amp;#39;s control tree.&amp;nbsp;The master page can then walk the Content controls that existed in the web form and bring them back them into the control hierarchy in the appropriate locations. The master page injection happens &lt;i&gt;after&lt;/i&gt; the PreInit event fires for a Page object, but &lt;i&gt;before&lt;/i&gt; the Init event fires. &lt;/p&gt;
&lt;p&gt;This ordering of events outlined above is important if you want to programmatically set the master page to use for a web form with the MasterPageFile property. This property must be set in the PreInit event (or earlier), like the code below. One the master page has injected itself into the control hierarchy it is too late to try to set a new master page for the web form. If you try to set the MasterPageFile property after the PreInit event fires, the runtime will throw an InvalidOperationException.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:0pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:0pt;FONT-SIZE:8pt;BACKGROUND:#ffffcc;PADDING-BOTTOM:0pt;BORDER-LEFT:windowtext 1pt solid;COLOR:#000000;PADDING-TOP:0pt;BORDER-BOTTOM:windowtext 1pt solid;FONT-FAMILY:Lucida Sans Typewriter Regular;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Protected&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Sub&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; Page_PreInit(&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;ByVal&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; sender &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;As&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Object&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;, _&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;ByVal&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; e &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;As&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; EventArgs) _&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Handles&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Me&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;.PreInit&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#008000;"&gt;&amp;#39; we can select a different master page in the PreInit event&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Me&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt;.MasterPageFile = &amp;quot;~/otc.master&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;End&lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;"&gt; &lt;/span&gt;&lt;span style="BACKGROUND:#ffffcc;COLOR:#0000ff;"&gt;Sub&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1832446.aspx</link><pubDate>Tue, 31 Jul 2007 11:37:51 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1832446</guid><dc:creator>MorningZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1832446.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1832446</wfw:commentRss><description>&lt;p&gt;&amp;quot;Is there something I am missing here&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Yes, that the only place you can change it is in the PreInit event, anything else is &amp;quot;too late&amp;quot;&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll have to get the user to refresh the page someway after selecting the new MasterPage choice, or have a response redirect after you save the setting&lt;/p&gt;</description></item><item><title>Re: Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1832414.aspx</link><pubDate>Tue, 31 Jul 2007 11:18:33 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1832414</guid><dc:creator>ravipahuja1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1832414.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1832414</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;http://www.exforsys.com/tutorials/asp.net-2.0/changing-master-pages-dynamically-in-asp.net-2.0.html&lt;/p&gt;</description></item><item><title>Changing Master Pages at runtime</title><link>http://forums.asp.net/thread/1832376.aspx</link><pubDate>Tue, 31 Jul 2007 10:51:22 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1832376</guid><dc:creator>Arjuna_Marambe</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1832376.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=139&amp;PostID=1832376</wfw:commentRss><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Is it possible to change the Master Page in the Postback.&amp;nbsp; I know you have to do it in the &amp;quot;OnPreInit&amp;quot; event but can you do it in a Postback.&amp;nbsp; The reason why I am asking this is because, in my site I am changing the Master Page at runtime in the &amp;quot;OnPreInit&amp;quot; even in a Postback and this causes a crash with the following error message.&lt;br /&gt;&lt;br /&gt;Failed to load viewstate.&amp;nbsp; The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.&amp;nbsp; For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. &lt;br /&gt;&lt;br /&gt;Is there something I am missing here.&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;Arjuna. &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>