How does Silverlight Call a Javascript Function in a Namespace?

I have a problem since I wrapped my javascript functions inside a namespace. Version 1 of my code worked fine. Initially, to call javascript from within Silverlight, I used this code:

HtmlPage.Window.Invoke("hideMyDiv"); 

My javascript looked like this:

 function hideMyDiv() { $('#MyDiv').fadeOut(); 

}

Now I reworked my javascript to be contained in the namespace. Now it looks like this:

 var activity = { message: null, hideMyDiv: function() { $('#MyDiv').fadeOut(); } }; 

I can call this refactored function in javascript, it works as before:

 $("document").ready(function() { activity.hideMyDiv(); }); 

But when I try to use it from Silverlight, I get this error: Failed Invoke: activity.updateInfo. This is my current Silverlight code:

 HtmlPage.Window.Invoke("activity.hideMyDiv"); 

What am I doing wrong? (and thanks!)

+6
javascript silverlight
source share
1 answer

This is the correct way.

 ScriptObject so = HtmlPage.Window.Eval("activity") as ScriptObject; so.Invoke("hideMyDiv"); 
+11
source share

All Articles