Click here to Skip to main content
13,589,969 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 24 Jul 2010
Licenced CPOL

How to Pass Values to Silverlight Application from ASPX Page using InitParameter?

, 24 Jul 2010
Rate this:
Please Sign up or sign in to vote.
I found various people in different forums asking for the logic on the implementation part for passing value to Silverlight application from ASP.NET application. In this post, I will describe it.

Neither is Silverlight new nor are the init params. But, I found various people in different forums asking for the logic on the implementation part for passing value to Silverlight application from ASP.NET application. In this post, I will describe it.

Here, I will discuss the InitParams and tell you how to use it to pass value from your .aspx page to your Silverlight application. Read the complete post and if you have any queries, don’t hesitate to ask me.

InitParams is one of the param names of the Silverlight plug-in object. Generally, it is a dictionary object of type string. It contains a set of user defined key/value pairs. By default, it is set as null or empty string and initializes at the time of first instance. Later, it becomes readonly and hence you will not be able to modify it. If you have more than one string values to pass, use comma separated key/value pairs. Have a look into it:

<param name="initparams" value="a=10,b=20" />

Here, I am passing 10 & 20 as two string values to the key names a & b respectively. Now you can retrieve the value in backend code by using the Key a & Key b. I will discuss it later.

Let us discuss about it in more depth. Your Silverlight application hosts in either HTML or ASPX page. In that page, you will find the following code snippet where you have an <object></object> tag. There are several <param /> tags inside it. Create one more param tag as mentioned above and set the value to that. See the code here:


Now, it is time to retrieve the code from your .cs file. Open your App.xaml.cs file. There, find the event named “Application_Startup”. This has a parameter called “StartupEventArgs” and contains property named “InitParams”. This will have the values you entered in the HTML/ASPX page.


Once retrieved, you can iterate through each key/value pair to read the values. Have a look into the below code:


In the above example, I read each of the initparam values and show with the help of MessageBox. So, what next? Now you can read the value and send it to your RootVisual UserControl/Page (i.e., MainPage in this example) by creating a parameterized constructor for the MainPage. There might be a question, “Do I have to read the values by iterating each key inside the App.xaml.cs and then have to send it to my Silverlight page?” Nope, not the case. You can send the whole dictionary to your MainPage and then you can iterate through each key.

Hope that now you got the basic idea on that & can read any values from your .aspx/.html page in your Silverlight application. But remember that you can only set these values once you are initializing the application. After the initialization is done, “initparams” becomes readonly and you will not be able to set/modify it anymore.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...


Comments and Discussions

GeneralGood Article to understand basic of initparams Pin
Pramodmca0912-Jan-11 18:12
memberPramodmca0912-Jan-11 18:12 
GeneralMy vote of 4 Pin
Pramodmca0912-Jan-11 18:11
memberPramodmca0912-Jan-11 18:11 
GeneralRe: My vote of 4 Pin
Kunal_Chowdhury12-Jan-11 18:15
mvpKunal_Chowdhury12-Jan-11 18:15 
GeneralRe: My vote of 4 Pin
yrishi8-Feb-11 2:45
memberyrishi8-Feb-11 2:45 
GeneralRe: My vote of 4 Pin
Kunal_Chowdhury8-Feb-11 3:44
mvpKunal_Chowdhury8-Feb-11 3:44 
GeneralGood one Pin
Abhishek Sur24-Jul-10 8:55
mvpAbhishek Sur24-Jul-10 8:55 
GeneralRe: Good one Pin
KunalChowdhury24-Jul-10 10:47
mentorKunalChowdhury24-Jul-10 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.180618.1 | Last Updated 24 Jul 2010
Article Copyright 2010 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid