Skip to main content
Home Forums Silverlight Programming Programming with JavaScript How to pass data using scriptableMember method
6 replies. Latest Post by Min-Hong Tang - MSFT on October 21, 2009.
(0)
chandi
Member
3 points
22 Posts
10-18-2009 7:36 AM |
Hi, I have asp.net web application and silverlight project.When I click a button in asp.net .aspx page it goes to silverlight project and there loaded event call to javascript. In that javascript call a scriptableMember method in silverlight project. The reason is to use scriptableMember method in silverlight project is to pass data from asp.net application to silverlight project. My problem is how can I pass values to scriptableMember method parameters from asp.net web application. Thanx
davidezo...
Contributor
5686 points
873 Posts
10-18-2009 8:23 AM |
Hi,
read this articles:
Hope this helps.
10-19-2009 3:53 AM |
Hi david,
Thanx for your reply.
I developed my application as second article.
Page.xaml
namespace SilverlightApplication{ public partial class Page : UserControl { public Page() { InitializeComponent(); HtmlPage.RegisterScriptableObject("Page", this); HtmlPage.Window.Invoke("TalkToJavaScript", "Hellofrom Silverlight"); }
[ScriptableMember] public void UpdateText(string result) { myTextbox.Text = result; } }}
<script type="text/javascript"> function TalkToJavaScript( data){ alert("Message received from Silverlight: "+data); var control = document.getElementById("silverlightControl");
control.Content.Page.UpdateText("Hello from Javascript!"); } </script>
Here UpdateText ScriptableMember method parameter value has hardcoded.
I need to pass my entered TextBox string to UpdateText method.
How can I do that.
Thanx
10-19-2009 2:28 PM |
You can use another [ScriptableMember]:
{
InitializeComponent();
}
[
myTextBox.Text = result;
alert(
control.Content.Page.UpdateText(control.Content.Page.GetText());
10-20-2009 4:47 AM |
Thank you very much for your reply.
In your example myTextBox is a xaml page control.
Actually I need a call method in asp.net according to entered value.
1. In my asp.net page there is a button.
2. When button clicked it pops up a child window which is in silverlight project.
3. In my child window there is a two combo box fields.
4. According to selected item in first combo, second combo should be populate.
5. This data populated method couldn't write in xaml.cs page as assembly reference not supported. Therefor it is in asp.net.so when I selected an item from first combo it goes to javascript function and from there should call a method.
Please help me.
Min-Hong...
3376 points
377 Posts
10-21-2009 3:09 AM |
Em, you mean after you selected something in your first comboBox then your code-behind should pass value to your javascript and then process it and generate some results and at last pass the result back to your second comboBox which is a silverlight control. If i didn't get you wrong. Then all you need is anther scriptablemember which can accept some value.
In your codeBehind:
[ScriptableMember] public void SetText(object e) { // do your stuff
Then in your asp.net page javascript you can just invoke it alike invoking the GetText() member. About how to dynamically add a control you can check links below.
http://forums.silverlight.net/forums/t/9298.aspx
http://forums.silverlight.net/forums/t/135977.aspx
Best Regards
10-21-2009 9:56 PM |
By the way, there are other ways to pass values from asp.net to SL application. Em, say to use InitParams or to use cookies.
http://msdn.microsoft.com/en-us/library/dd920298(VS.95).aspx This link show how to get and set cookies in silverlight application.
http://msdn.microsoft.com/en-us/library/cc838255(VS.95).aspx This link show how to use InitParams.
And hope you find the best solution as soon as possible.