Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Calling Javascript method from Silverlight, passing extra parameters
6 replies. Latest Post by mchlsync on December 29, 2007.
(0)
brauliod
Participant
1169 points
472 Posts
12-25-2007 11:56 AM |
Hi,
I have seen several samples about how to call a javascript function from silverlight, that's nice, but... all samples does not pass any extra param to the javascript method (using the other way around, call from javascript to ajax you can add for instance extra string params). Anyone has a sample about how to do this, or add extra params to the EventArgs?
Thanks
Braulio
mchlsync
Star
14606 points
2,730 Posts
12-27-2007 12:45 PM |
brauliod:add extra params to the EventArgs
What do you meant by "extra parameters" ? You mean, you want to pass the unlimited numbers of parameters to Javascript function?
12-27-2007 4:54 PM |
Just add my custom fixed parameters, e.g. several strings (I guess I can pass just some basic types, string, number...)
12-27-2007 9:53 PM |
I think it doesn't support or still has some bugs for that.
I reported it in this link. you can track it.
Brauliod
12-28-2007 7:21 AM |
Thanks for the info, in the mean time I will use HTML hidden fields as a workaround.
robert.p...
Member
116 points
37 Posts
12-29-2007 5:16 AM |
http://silverlight.net/forums/t/7729.aspx
You need construct your own EventArgs in CallbackToBrowser(this, new EventArgs());
How do it you find in msdn it's simple.
12-29-2007 5:36 AM |
I forget to put [Scriptable] in my EventArgs class. You can try the code below. I hope it works.
The new EventArgs class with parameters
[Scriptable]public class EventArgs<T> : EventArgs{ private T _data; public EventArgs(T args) { _data = args; } public T Data { get { return _data; } } }
Page.xaml.cs
[Scriptable] public partial class Page : Canvas {
public Page() { WebApplication.Current.RegisterScriptableObject("EntryPoint", this); MouseLeftButtonDown += Page_MouseLeftButtonDown; } void Page_MouseLeftButtonDown(object sender, MouseEventArgs e) { if (CallbackToBrowser != null) { CallbackToBrowser(this, new EventArgs<string>("my value")); } }
[Scriptable] public event EventHandler CallbackToBrowser;
}
TestPage.html.js