views:

256

answers:

1

I'm having a problem since I wrapped my javascript functions inside of a namespace. Version 1 of my code worked fine. Originally, to call the javascript from inside Silverlight I used to use this code:

HtmlPage.Window.Invoke("hideMyDiv");

My javascript looked like this:

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

}

Now, I've refactored my javascript to be contained in a namespace. So it now looks like this:

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

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

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

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

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

What am I doing wrong? (and thanks!)

+5  A: 

This is the correct way..

ScriptObject so = HtmlPage.Window.Eval("activity") as ScriptObject;
so.Invoke("hideMyDiv");
Akash Kava
Thank-you, works like a charm.
BPerreault