WynApse Home Page
Home    Blog    About    Contact       
Latest Article:

My Tags:
My Sponsors:

Lifetime Member:

Silverlight Loaded and OnLoad Tests

Post-testing Update

It's taken me a while to get back to this, and actually at first it didn't seem necessary because the code change was listed on my blog, but after time passes, I've had some questions about it and I've said "yeah... I wrote that up, umm... oh... it's on my blog, not with the article... sorry"!

This all came to a head very quickly after I tried running the code from my site rather than from localhost.

The code didn't run when I first tried it... it threw a JavaScript error saying it could not find the OnLoad function. View->Source proved I was not losing it, the code was right there... near the bottom of the file where I expected it to be. Something about the fact that it was near the bottom made me start questioning my reasoning for that.

Normally when I inject JS from the database it ends up at the bottom of the file, so maybe I thought I should add the JS down there. The whole location of the JS and injection got me to question everything, so I looked up the manner of injection I was using: ClientScript.RegisterStartupScript.

When I looked that up, I found that function was deprecated and I should be using ClientScriptManager instead. I finally ended up with this:

ClientScriptManager csm = Page.ClientScript;
Type cstype = this.GetType();
csm.RegisterClientScriptBlock(cstype, sEvent, sMarkupJS);

'sEvent' is the database ID of the article, and 'sMarkupJS' is the JS for the article. These are the same as I used in the previous version of the code.

But... this only holds for the injected JS. The JS for the OutlookBar is onboard because it's part of my MasterPage, so what's up with that?

Fact is, when I modified the injection, the JS ended up being located higher in the file, so I took that as a clue, and relocated the MasterPage JS up there as well, and everything started working!

Now the OutlookBar comes up *EVERY* time ... even on my BlogRoll page and my Admin page, which it never did before. Also, the GlyphMap Tool is solid in IE6 which is a huge relief.

Maybe this will save someone some debug time, or possibly keep someone from pulling out their hair :)

Whatever for?

That is THE question of the day... why the heck would I do such a page, and if you found yourself here without having read any other of my posts, I'm sure that question came to mind.

So let's back up just a bit. I was pretty proud of my GlyphMap Tool, it has skin, it has sliding-panel menus, transparent areas, flyover tooltips, and was actually done while still running beta WPF/E. The only issue was that people started telling me "it doesn't work". Hmmm... (insert standard programmer comment here) "It Works on MY machine". But wait, MY machine is IE7, and umm... let's see these guys are running FireFox. Since it was reported to me while I was at the office, I couldn't test that, but I did try it on IE6 and wow... it's not solid. As a matter of fact, I tried it as I was looking up the URL for this paragraph, and I got no center content displayed, plus an error: "control.content is null or not an object".

Then the latest big thing that has problems is My Silverlight Outlook Bar. That sucker works 100% of the time on IE7, but about 30 to 40% of the time on IE6, the starting canvas never gets loaded, so I see "Loading Menu..." and that's not good.

I've been talking about this since something like April of 2007, so finally decided to take a whack at some sort of display to show the issue.

The secondary 'big deal' about this is that it works just wonderfully locally. Since I'm doing 1.0, I'm building html pages. The pages just work fine, I don't care how I try to display them. It's not until they get deployed and displayed across the web that they become problem children in IE6 (and FF?). So to that end, as I'm building this page it seems like a ridiculous exercise.

Displaying What

I decided I'd display everything I could that has to do with the Silverlight page. Since this is going to be displayed from the database into the content area of a subpage, I'm not going to be able to display information when the HTML Body OnLoad hits. I suppose I could if I modified my MasterPage and only answered up to the call on this page, but I'm not sure I really want to do that if I can avoid it.

So that leaves me with just a couple things to display. I actually increased it to 3 by adding a canvas around my TextBlock. So the three display values are:


This is a common Loaded= function called by the loading of the canvas containing the TextBlock.


This is a common Loaded= function called by the loading of the outer canvas.


OnLoad is called when the Silverlight control for this canvas is loaded. It is set in the createObjectEx call, and provides access to a few values.

From OnLoad, we can get the id of the control for the canvas being loaded. We can get a userContext value that is another parameter to createObjectEx, and we also get back the sender

JavaScript for producing this page:

<script type="text/javascript">

var sOutput = "";


function SLLoadedOnLoadTestCanvasLoaded(sender, args)


   sOutput = "Loaded=" + sender.Name + "\n";




function SLLOLTOnLoad(control, userContext, sender)


    sOutput = "OnLoad, control.id: " + control.id + ", userContext: " + userContext + ", sender: " + sender.Name + "\n";




function PageOnLoad()


   sOutput = "PageOnLoad fired\n";





Where 'Output' is simply an html textarea on the form.

XAML for producing this page:







    <Canvas x:Name="InnerCanvas"


      <TextBlock FontSize="14"




                  Text="Hello" />





So Now What?

I can see what the results are here immediately on IE7 and FireFox, and will include them on the blog post I announce this with. From the office I can see what I'm getting for IE6, and will blog about them as well. Hopefully what I'm going to see is some inconsistencies. Either that or I'll be more confused than I am now.

I was going to try to build in a webservice to take some metrics, but I'm going to hold off on that until I see what this does from the site, and in IE6. If it indeed isn't working correctly, I'll start capturing data and then see about getting the info to someone that can do something about it. For now the display is only on this page.

Copyright © 2006-2022, WynApse