.NET Blog

Tony Cavaliere

 
My Favourite Albums
  And the Grappa wins.
E-mail me Send mail

Disclaimer

Hey unlike other bloggers I stand by what I say but just in case. The opinions expressed herein are my own except on Tuesday when the second card is not turned up otherwise it ain't worth squat.

© Copyright 2012

Calling Complex jQuery from Silverlight: Eval to the Rescue

In an earlier post I described how you can call jQuery from within a Silverlight application. The process is rather simple as was the example. Please refer to the original post for further details.

Afterwards I began to think about calling more complex jQuery constructs from within Silverlight. What about registering events and using anonymous functions? At first glance it didn’t seem it was going to work at least not with the technique I described in my earlier post. Then I discovered the dark side of Javascript the Eval function. The Silverlight HtmlPage.Window object exposes the Eval function that allows you to evaluate any string.

I added the following line of code to my the Page constructor for the example from my previous post.

   21    HtmlPage.Window.Eval("$('#hello').click(function() { alert('Eureka'); });");

This code basically registers a click event with the DOM element with id of #hello. When the DOM element is clicked an alert is displayed and it works perfectly well.

As with raw Javascript all the pros and cons with the use of Eval exist when used from within Silverlight. But it’s good to know that if required complex Javascript functionality can be implemented from within Silverlight.

Currently rated 2.0 by 4 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: jQuery | Silverlight
Posted by CynotWhyNot on Friday, March 20, 2009 10:41 AM
Permalink | Comments (3) | Post RSSRSS comment feed

Related posts

Comments

answerspluto.com

Monday, July 13, 2009 9:56 PM

pingback

Pingback from answerspluto.com

list of urls - 5 « Answers Pluto

discount designer bags US

Thursday, May 27, 2010 2:34 PM

discount designer bags

You have a point. Very insightful. A nice different perspective

discount wallets online US

Monday, May 31, 2010 3:07 PM

discount wallets online

I find your blog in google. And I will be back next time, thanks.