This Article will help to understand how the initial data required by Silverlight Application will be transfer to it from ASP.NET Page. This helps in transferring dynamic settings from ASP.NET Page to Silverlight application
Introduction
It is always required to transfer some data and details while starting a Silverlight application. These data are mostly required to init Silverlight application like URL for data service or some settings that are required to transfer from Web Application. This Article will help to understand how we can achieve using ASP.NET.
ASP.NET Sample
Create a new Silverlight application as discussed in Silverlight Part 1.
Go to ASP.NET Web Application and to Silverlight ASPX Test Page as below and Enter the data that you want to transfer to Silverlight. It is called InitParams in Silverlight application.
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightApplication1.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<param name="InitParams" value="Param1=Test1234567890" />
These parameters can be accessed in your Silverlight Application in Application Init even as below.
Go to Silverlight application and App.Xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage(e.InitParams["Param1"]);
}
The above code transfers data to MainPage using constructor and we can set this data as Content to button as below
public MainPage(string cSetting)
{
InitializeComponent();
TestBtn.Content = cSetting;
}
<Button Grid.Row="0" Grid.Column="0" Content="Test" x:Name="TestBtn">
</Button>
Conclusion
This Article just shows how we can transfer Init parameters from the ASP Page or Html Page to Silverlight Application. You can set the same using ASP.NET Server Control through ASP.NET Code Behind Dynamically.
In real time scenarios Init Parameters are widely to transfer Dynamic Settings which will be controlled by ASP.NET Code which will be executed and creates setting dynamically based on the requirements.