What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Wednesday, February 07, 2007

I'm doing one of the most complicated UI I've ever did(ASP.NET). In the process, I need to generate tabs(via MultiView control) pragmatically and for each tab render a tree-like checkboxes. All based on external xml. Yami.. ;-)

Reading a little about how to add dynamic View to MultiView control made me realize that I need to do my magic on the page's PreInit event. This one was quite easy, I've override the OnPreInit (I could register to the event in the page constructor, but this is easier) and called my dark voodoo "BuildTabs" method. All is good.

Now, Adding MasterPage to the blend made me puzzled for a few minutes. It seems that the page's controls are not initialized on the PreInit phase if the page has MasterPage. After I got my eyes back on the screen, stop nodding with disappointment and taking my head off the wall, I used my built-in behavioral program:

pre-think (short phase ~Thread.Sleep(1000*60));
while(no solution yet) { 
   try;
   think;
}.

2 minutes later I found the trick:

protected override void OnPreInit(EventArgs e)
{
   base.OnPreInit(e);
   base.Master.Init += new EventHandler(Master_Init);
}

void Master_Init(object sender, EventArgs e)
{
   BuildTabs(); //we must draw it from scratch on each post-back.
}

Now the controls are initialized and I can program in peace.

Posted by Oren Ellenbogen 
07/02/2007 11:47, Israel time UTC+02:00,     Comments [2]  | 
Thursday, February 08, 2007 12:14:37 PM (Jerusalem Standard Time, UTC+02:00)
Just a small note about the registration to the PreInit event: Is there a reason you're not using the AutoEventWireup property? It means that in order to sign up for the event you just have to write:

protected void Page_PreInit(...)

And the page will sign you up automatically.
Friday, February 09, 2007 10:08:35 PM (Jerusalem Standard Time, UTC+02:00)
Hey Doron.
I'm familiar with the solution. I guess that I'm used to override the required method or explicitly register to the event(no special reason by the way). But I'll make the change as I believe your suggestion will make the code clearer. Thanks.
Comments are closed.