Call JavaScript function from Silverlight 4.0 application

Posted by Raha on Stack Overflow See other posts from Stack Overflow or by Raha
Published on 2010-05-13T00:35:27Z Indexed on 2010/05/13 0:44 UTC
Read the original article Hit count: 267

Filed under:
|

I am trying to call a function from a Silverlight application. It should be a very simple task to do but so far I am not getting the result that I am looking for.

This is my Silverlight code:

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        HtmlPage.Window.Invoke("SayHello", new string[] { "Salut!" });
    }

And this is the JavaScript code :

   function SayHello(theid) {
        alert(eval(theid));
        var divStatusDiv = document.getElementById("divStatus");
        divStatusDiv.style.backgroundColor = "Red";
    }

The alert message always show "undefined" but when I press "OK" the colour of that DIV gets changed to Red as it should be.

Why am I getting "Undefined" all the time ?

© Stack Overflow or respective owner

Related posts about silverlight-4.0

Related posts about JavaScript