I’m using the concepts taught in this tutorial to communicate with Javascript to and from my Silverlight app. I want the JavaScript code to check to see if all the form fields on the HTML side are filled in, and if so, run a method in MainPage.
The problem is that this technique returns a response to the ScriptableClass object, instead of the MainPage. Does anyone know how the ScriptableObject can call a method in the MainClass. Perhaps using an event in the MainClass triggered in the ScriptableClass object?
public class ScriptableClass
{
[ScriptableMember]
public void gotdetails(string message)
{
if (message == "1")
{
// call next method in MainPage
}
if (message == "0")
{
// tell user to complete fields
}
}
}
One solution is move you “gotdetails” method to MainClass and register this MainClass as ScriptableObject, I mean you not need ScriptableClass at all.
Second option, if you want to keep ScriptableClass, is create static event in ScriptableClass and subscribe to this event in MainClass. With static event you not need to have access from MainClass instance to ScriptableCalss instance.
MSDN also have good walthrough about javascript and Silverlight communication .