Tuesday, March 11, 2008

Passing values from website to Silverlight control

Here is one simple technique to pass values from website (aspx page where Silverlight control resides) to silverlight control.
This employes the InitParameters property of silverlight control to hold the values.

<asp:Silverlight ID="Xaml1" 

runat="server"

Source="~/ClientBin/MySilverlight.xap"

Version="1.1"

Width="1024px" Height="768px"

PluginBackColor="#0C0C0C"

InitParameters="Name=Joy"/>

In Silvelight application (App.xaml.cs)



private void OnStartup(object sender, StartupEventArgs e)

{

Page p = new Page();

p.UserName = e.InitParams["Name"];//Accessing initParams

this.RootVisual = p;


}

2 comments:

Unknown said...

Either you have a typo in your example or ASP is doing the work for you. If you want to define InitParameters directly in the object tag (e.g. in an php page) use InitParams instead.
<param name="InitParams" value="foo=bar" />

Joymon said...

Thanks for your comment.
Here Silverlight object of asp.net is doing the work for me.