Silverlight Monday for January 21, 2008 - #3 - Silverlight Loaded and OnLoad Tests

If you've been following along reading my postings, you'll know that I've been casting aspersions about the canvas Loaded= event at least on IE6 and maybe FireFox. I've got a couple Silverlight applications that just are not solidly functional in IE6 and FIreFox (at least) and the only thing that made sense was that Loaded= didn't always fire.

So to finally 'put that to bed', I decided to write a simple little demo to test that, and as long as I was doing so, I included the OnLoad event as well:

Silverlight Loaded and OnLoad Tests


I won't know until I get to the office later this morning, but I'm almost 100% positive that not only does this page show that Loaded= works just fine, but it found my problem as well!

When I ran this from my site, it didn't work. It threw a JS error saying it could not find my OnLoad function. I did view->source and it was very obviously there at the bottom as I expected. I started having some feelings of dejá vu about that, and decided to look deeper.

All my content is stored in SQL, and I have a process to pull out the markup and display it. For 1.0 this works just great, but I'm not sure what I'm going to do in 2.0 (note to self: worry about that later). When I started doing JS with Silverlight, I needed a way to get the JS into the picture, so I used ClientScript.RegisterStartupScript.

Last night I went looking at that method. I'm not sure exactly why, but it was advantageous because I found that function was deprecated and I should be using ClientScriptManager instead! After a bit of fumbling around, 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 JavaScript for the article. These two are the same as I used previously.

When I deployed that to my site, the OnLoad event started working on the new page. I immediately fired up FireFox and found no issues there

Bottom Line...

I built this page to test Loaded= and OnLoad and find out where the issues were, and it appears, at least initially, that I may have found them... in my code!

The difference is that previously the JS *was* injected, but it was near the bottom of the page, and apparently not fully alive at the time it was needed. Now the JS is near the top. I'll update about this after I test it in IE6 this morning.

Stay in the 'Light!

Silverlight News on Twitter | Silverlight Tagged Web Articles | My Articles | My Tutorials | My Tooltips | SilverlightCream

posted @ Monday, January 21, 2008 6:32 AM

Print

Comments on this entry:

# re: Silverlight Monday for January 21, 2008 - #3 - Silverlight Loaded and OnLoad Tests

Left by Bill Reiss at 1/21/2008 7:43 AM
Gravatar
Thanks for this, I've been seeing some strange behavior occasionally and this could explain it.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 5 and type the answer here:
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011