I ran across this article at CodeProject and I started to implement it in my new project. The basic idea behind it is to parse a child page (Context Page) and before Viewstate is even loaded, it does a Server.Execute to execute the desired master page, and the master page just loads its controls into the HttpContext (it makes sure not to render itself). The execution resumes at the Context page and the entire control collection of <form> is copied into a specifically named control and finishes execution!
<html> ... //header & navigation <div id="masterContextContainer"> </div> //footer </html>
That's it! Mark the class with the [MasterPage()] attribute and it's ready to go!
The Context Page is just a normal aspx page that has the class marked as [ContextPage(masterPageAlias)] and it's done.
There are a number of different methods to accomplish this, but I found this one to be very nice because A) I can inherit my PageBase class from this MasterContextPage and start using it on existing web forms... B) it's very clever!
I'm Ben Scheirman. I am a .NET software developer with a strong interest in agility. I work as a Principal Consultant with Sogeti.
Read more here.
email me
Ads by The Lounge
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.