Hi All,
In this short post I will explain you how to pass initial parameters from aspx page to Silverlight application. So let’s get started. In this simple application we will create default.aspx page with two textboxes and pass them using query string parameter to other page and on that page we will host a Silverlight control. The passed query string parameter will be passed to this Silverlight control.
So let’s get started.
Step 1:-
The first thing we want to do is to create a Silverlight application shown as below. Make sure to add Defautl.aspx page and set that as a startup page. Also make sure to add couple of textboxes and a button. Clicking on this button will take value from two textboxes and pass it across to other aspx page with those values as QueryString parameter. SilverlightParamsTestPage.aspx page contains Silverlight control.


Modify the defautl page click event like below.
protected void btnSilverlight_Click(object sender, EventArgs e)
{
string Param = txtFirstName.Text + " " + txtLastName.Text;
Response.Redirect("SilverlightParamsTestPage.aspx?Param="+Param);
}
Step 2:-
On the page where we have hosted a Silverlight control modify it’s source code and handle it’s Page load event to read the query string parameter so we can pass it as an initial parameter to the Silverlight. In this page we have kept only one file for HTML and code behind.
<script runat="server">
private string InitParam = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString != null)
{
InitParam = "User=" + Request.QueryString["Param"];
}
}
</script>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightParams.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="<%=InitParam %>" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
<iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>
As you can see we define a string on default page and set it’s value to what we are getting as a QueryString parameter. And we define one param to Silverlight object named InitParams and set it’s value to the string we defined on the page.
The value being generated will be as User = Test Param
If you want to pass multiple parameters it can be generated with comma separated key-value pairs. For example
User = Test Param,User2=Test Param2,User3=TestParam3
Step 3:-
Next we need to do is access this value into Silverlight application. In the Silverlight application’s App.xaml.cs page we will access this InitParas. From here we will pass that to MainPage into it’s constructor and finally display this value into a textblock placed on MainPage.cs

That’s it. As I mentioned earlier this is what you need to do for passing parameters from aspx page or a UserControl to your silverlight client/control.
Thanks