Page view counter
Interaction between Silverlight controls
Last post 05-20-2008 11:26 AM by ladito9482. 2 replies.
Sort Posts:
05-20-2008 10:49 AM
Interaction between Silverlight controls

Hi all, 

My idea is to use Silverlight controls in my aspx. Perhaps this is not the way Silverlight should be used but I think It could be an interesting feature for ASP.NET. 

I`ve an ASP.NET Web Page which have three <asp:Silverlight controls. One have a textbox, the other is a grid and the tirdth is a button. I use the same .xap an I pass the type of the control I want to load in the InitParameters. Then in the Application_Startup I create the control depending on the parameters (This way was expained in some post in this forum)

Now I would like to add an item to the grid when the button is clicked. The text of this item comes from the textbox :)

When the button is clicked I excecute javascript code using:

[ScriptableMember]

public event EventHandler ButtonClicked;
public Boton()

{

InitializeComponent();

HtmlPage.RegisterScriptableObject("ScriptablePageObject", this);

}

private void btn_Click(object sender, RoutedEventArgs e)

{

if (ButtonClicked != null)

{

ButtonClicked(sender, e);

}

}

 and

function pluginLoaded(sender,args) {

var slCtl = document.getElementById("Xaml3");

slCtl.Content.ScriptablePageObject.addEventListener("ButtonClicked", jsEventHandler);

}

 

function jsEventHandler(sender, args) {

alert("Se pulso el boton");

}

The problem I`m facing now is that I`m not able to interact between controls from javascript. For example, get the text from textbox or add values to the grid.

Is there any solution?

Thanks in advance

ladito9482

Loading...
Joined on 05-20-2008
Posts 3
05-20-2008 11:05 AM
Marked as Answer
Re: Interaction between Silverlight controls

If you want to get the text from the textbox and then add it to the grid, you have to add scriptable functions in the Silverlight code to do so and then call those methods from JavaScript.

Unless you *reaaaally* have a requirement for this kind of architecture, I would advise against it. You decrease your performance and at the same time increase your code and architecture complexity by running components in separate plugins and hooking them together with JavaScript when they should all be running under the same plugin - this is analogous to making a Windows program with a Textbox, another with a Grid, a third with a Button, and making them talk to each other via DCOM. Yes, you can do it, but I pity the fool who has to maintain it down the road Wink
 

Jabb

Loading...
Joined on 03-06-2008
Posts 73
05-20-2008 11:26 AM
Re: Re: Interaction between Silverlight controls

Thanks Jabb,

Due to your excelent response I'm reading Walkthrough: Calling Managed Code from Client Script now Smile

Thanks !!

ladito9482

Loading...
Joined on 05-20-2008
Posts 3
Microsoft Communities