views:

573

answers:

2

For example:

First, say I have a Silverlight app with Windowless=true so that I can place ASP.NET controls on top of it. Then I place an ASP.NET button on the page. How can I have say the text of a control in the Silverlight app change when the user presses the ASP.NET button? How would I send the Silverlight app an update message from the C# code that catches the Click of the ASP.NET button?

Thanks, Jeff

+1  A: 

From what I can tell, based on your question, the Silverlight application is running in a web browser and you have it embedded in an asp.net page? The code for the asp.net button that you are dragging on the page lives on the server and gets sent to the web browser as html. When you click the button on the page it is submitting form data back to the server which ASP.NET interprets and calls your button click code. Since that code is executing on the server it cannot get to the silverlight app. If you really need to interact with the silverlight application directly on the client you would use javascript in the browser.

Here is a basic example: http://blogs.vertigo.com/personal/ralph/Blog/archive/2008/05/15/call-silverlight-from-javascript-call-javascript-from-silverlight.aspx

duckworth
+1  A: 

From memory, you need to expose a scriptable member from your silverlight application, eg:

[ScriptableMember()]
public void ChangeText(string newText)
{
    // Update your text control here
}

and register it for scripting from javascript in the constructor:

public MySilverlight()
{
    InitializeComponent();
    HtmlPage.RegisterScriptableObject("MyObject", this);
}

You can then invoke it from javascript as;

function ChangeText()
{
    var yourObject = getElementById("yourObjectID");
    yourObject.Content.MyObject.ChangeText("New Text");
}

Then just wire up the button's client click to invoke the javascript ChangeText method.

Hope this helps.

deepcode.co.uk