Answered by:
Problem with scriptable objects

Question
-
Hi,
I would like to send an event to my javascript when I'm done with a certain action within Silverlight code (like upload succeeded) .
For that purpose I would like to use a scriptable object.
In the onLoad function in javascript, I get this error "Trying to get unsupported property on scriptable plugin object!". And I can see in the Debugger that control.Content doesn't have a property SilverlightControl although this is the name I used when I call RegisterScriptableObject in my C# code.
Here is my java script:
function uploadSuccess(sender, args)
{
alert('Upload succeeded!');
}
function onLoad() // call the onLoad function on the body onLoad event.
{
control= document.getElementById('Xaml1'); //Xaml1 is the id of my silverlight object in html
control.Content.SilverlightControl.OnUploadSuccedeed = uploadSuccess;
}Here is my code:
[ScriptableType]
public class UploadSuccessEvent
{
[ScriptableMember]
public event EventHandler Event;
public virtual void OnEvent(UploadSuccessEventArgs e)
{
Event(this, e);
}
}
[ScriptableType]
public class UploadSuccessEventArgs : EventArgs
{
private string value;
[ScriptableMember]
public string Value
{
get { return this.value; }
set { this.value = value; }
}
}public partial class Page : UserControl
{public UploadSuccessEvent UploadSuccessEvent = new UploadSuccessEvent();
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
HtmlPage.RegisterScriptableObject("SilverlightControl", UploadSuccessEvent);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
uploadSuccessEvent.OnEvent(null); //At that point I get a null reference exception because uploadSuccessEvent.Event is null.
......
}
}
Does anybody have an idea?
Thank you
Thursday, July 24, 2008 11:01 AM
Answers
-
if you have javascript function like
abc(a)
{
alert(a);
}
then call like below code
HtmlPage.Window.Invoke("abc","sachin");
for using this add
using System.Windows.Browser;
C#
HtmlPage.Window.Invoke("abc","sachin");
Monday, July 28, 2008 7:08 AM -
Thanks, your solution is much easier than the scriptable objects.
Alexandra
Wednesday, July 30, 2008 8:51 AM
All replies
-
if you have javascript function like
abc(a)
{
alert(a);
}
then call like below code
HtmlPage.Window.Invoke("abc","sachin");
for using this add
using System.Windows.Browser;
C#
HtmlPage.Window.Invoke("abc","sachin");
Monday, July 28, 2008 7:08 AM -
Thanks, your solution is much easier than the scriptable objects.
Alexandra
Wednesday, July 30, 2008 8:51 AM