Tuesday, December 6, 2011

Calling Silverlight Method from Javascript and Javascript Function from Silverlight


When working with silverlight, we are working with manage code (C#,VB). sometimes we will need to callback to html page from manage code.

In this article we walkthrough how to calling manage code from javascript and calling javascript function from manage code. 


To call javascript function from silverlight, HtmlPage class of System.Windows.Browser namespace is used to allow user to access and manipulate browser DOM (Document Object Model).

ScriptableMemberAtrribute class indicates that method or property is accessible for javascript caller.

To permit user to access method of silverlight from javascript you have to set [ScriptableMember] attribute to that method.

Using the code

Let's start with step by step including source to demonstrate how to communication between javascript and silverlight.