Monday, December 08, 2008

Silverlight instead of JavaScript?

I would not recommend anyone to use Silverlight instead of JavaScript, because of low tolerance of the former to browser differences. Besides, why would you trade your almost strongly typed JavaScript to weakly typed Silverlight syntax like:

HtmlElement label1 = HtmlPage.Document.GetElementById("Label1");
label1.SetProperty("innerHTML", "Dino");
However there is one scenario that could provide a good case for using Silverlight in place of JavaScript, as described here: http://msdn.microsoft.com/en-us/magazine/dd148642.aspx . Look at this piece of code:

HtmlElement button1;
button1 = HtmlPage.Document.GetElementById("Button1");
button1.AttachEvent("click", new System.EventHandler(Button1_Click));
You can attach a managed event handler to an HTML button!