views:

44

answers:

3

Hi, I have a real basic Silverlight app consisting solely of a label within an ASP.NET web page. It is included as an object.

If I want to change the Silverlight's label content via a button placed on the ASP.NET page. Could anyone provide a sample on how to do this both via javascript and server side via c#?

Thanks.

A: 

This is explained here (scroll down to "Call Silverlight Methods From JavaScript"): http://pietschsoft.com/post/2008/06/Silverlight-and-JavaScript-Interop-Basics.aspx

Konamiman
+1  A: 

Silverlight is a client-side technology, so you can't access it directly from server.

However, you can use its scripting capabilities to achieve what you want. For instance, you ASP.NET button could write some javascript which will interact with you SL app.

// Silverlight code
[ScriptableMember]
public void Start()
{
    // do something
}

// Javascript code
function start() {
    if (confirm("Are you sure?")) {
        document.getElementById("<%= SilverlightUpload.ClientID %>")
                .content.myControl.Start();
    }
}
Rubens Farias
$find gives me errors, even if i have Silverlight.js included..
pistacchio
try to use document.getElementById, as in edited answer
Rubens Farias
+1  A: 

Silverlight and JavaScript Interop Basics

opek