Multiple MasterPages and Atlas...

[out of date post... this deals with MS Atlas CTP... which has been change drastically and is now MS Ajax Extensions]

I discovered how to do something today that I want to remember (as well as to share with the world).  But before I do that I must say something… (I know it’s a repeat statement, but it’s still nice to say, and I started this post before I wrote my other one)

I love the Atlas UpdatePanel!!!!!

Ok, now that that’s off my chest.  We can delve into the mysteries of easily working with sites that have mutliple Masterpages and Atlas.  I’m currently working on a project where the application renders itself based on the url passed to it.  If the URL is localhost then you get one skin if it’s SomeOtherSite.com you get an entirely different rednering of the site.  I have a base page class that all other pages inherit from.  This BasePage contains logic to automagically place the correct MasterPage (something I’m not going to go into here).

Each Masterpage has a ScriptManager component in it (yep, that means I’m shoveling the Atlas client down on every page which may be a bit inefficient, but it should get Cached when I’m running with debug=”false”.

I decided to not expose a ScriptManager property (and yes, you can always search for the control in the MasterPage from your individual page, but I wanted something a little more elegant).  I decided to expose just the EnablePartialRendering property.  So I added the following code to my BaseMasterPage (all my MasterPage CodeBehind’s inherit from this class):

private bool _AtlasPartialUpdates = false;

/// <summary>
/// Gets or sets a value indicating whether atlas uses partial updates or not.
/// </summary>
/// <value><c>true</c> if [atlas partial updates]; otherwise, <c>false</c>.</value>
public bool AtlasPartialUpdates
{
  
get { return _AtlasPartialUpdates; }
  
set { _AtlasPartialUpdates = value; }
}

[Yep, I use GhostDoc, too].  This let’s my pages access the Partial Updates.  (BTW, I set the  <% @MasterType %> on all my pages to this BaseMasterPage type, so I don’t need to cast the page’s Master property to this type).

Another thing I discovered is that You can’t change the setting of EnablePartialRendering beyond the PreInit event, so I have to make this decision early on… That’s actually easy… each page either uses Partial Rendering or it doesn’t.  So in the PreInit event of each page that needs Partial Rendering (for UpdatePanels), I simply set this property to true via the page’s Master property.  It looks like this:

protected
override void Page_PreInit()
{
   Master.AtlasPartialUpdates =
true;
}

Since MasterPage PreInit happens after the Page PreInit I can do this in each master page-

protected void Page_PreInit(object sender, EventArgs e)
{
   ScriptManager1.EnablePartialRendering = AtlasPartialUpdates;
}

Now I can use the UpdatePanel on any page I want.  I also have enabled Atlas functionality on my entire site (I can just use controls… well, the UpdatePanel at least).   That’s it (I hope this helps someone else)…

[tags: Atlas, Ajax, ASP.Net, MasterPages]

Print | posted on Friday, April 28, 2006 6:00 PM

Feedback

# re: Multiple MasterPages and Atlas...

left by at 4/28/2006 8:12 PM Gravatar

What would the logic be like to have a base master page that could redirect to other master pages?  Could you give a code example?  Am I overcomplicating this in my mind or no?  

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 3:19 PM Gravatar

I'm attempting to implement the same sort of functionality.  How did you hook up the Page_PreInit in the master pages.  A code example would be great.

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 5:38 PM Gravatar

Karl,

You are... basically you have a Base MasterPage that all other MasterPages inherit from.  Remember I'm all about calling methods in the current page (not some other page... if you want to do some other page you will probably want to use a Web Service instead)

Jay

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 5:39 PM Gravatar

Steve,

Uhmmm... Code Sample is what this is...  Accckk!!  I messed something... let me fix (that's what I get for not using a project built as a sample)...

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 5:43 PM Gravatar

Steve,

That should be better... All you really need to do is read closely where I'm doing the page_preinit's.  The first one is for each page that wants to use an updatepanel and the second goes in every MasterPage.  You do have to build a BaseMasterPage class and inherit that class in each of your MasterPages.

I hope that helps...

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 6:31 PM Gravatar

Thanks for the responses.  Let me try to be a bit more clear on my question.  System.Web.UI.MasterPage does not have a PreInit event.  System.Web.UI.Page does have a PreInit event where Master.AtlasPartialUpdates = true; gets set.

How are you wiring up the MasterPage's PreInit event so you can set ScriptManager1.EnablePartialRendering = AtlasPartialUpdates;?

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 7:07 PM Gravatar

Steve,

I don't know what the official docs say, but if you put the code I have above in your MasterPage, the PreInit event will fire... (provided you have autoevent hookup turned on... I think)

Ray Lewallen had an old poster containing the various events in ASP.Net 2.0 (beta) and MasterPage PreInit is one of them... so Page_PreInit is an event that can be used in the codebehind of a MasterPage...

Jay

# re: Multiple MasterPages and Atlas...

left by at 5/9/2006 8:09 PM Gravatar

Well... the Page_PreInit event is officially not fired in my MasterPage with AutoEventWireup turned on.  However, I was able to get this to work using a slightly different approach...

I'm still using the PreInit of the page to set Master.AtlasPartialUpdates = true;.  For the MasterPage property, I am doing the following:

public bool IsAtlasPage

   {

       set

       {

           m_atlScriptManager.EnablePartialRendering = value;

       }

   }

Not as graceful, but as long as the property is set during PreInit, all is well.

Thanks again.

Steve

# re: Multiple MasterPages and Atlas...

left by at 5/15/2006 6:51 PM Gravatar

Hi Jay,

Can you please please help me out with this ..

We have a web page with a javascript menu on the left hand side. On click of the javascript menu, we want some content to be displayed but without the whole page getting refreshed. We are using master pages with the menu in the master page. But how do I see to it that the whole page does not get refreshed. I am Ok even with not using a master page..

Title  
Name
Email (never displayed)
Url
Comments   
Please add 2 and 5 and type the answer here: