Featured Post

Web API Requests Series

Web API Series:  Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows

06 April 2011

Passing data from a Form to an embedded Silverlight web resource.

In this post I will show how to pass data to an embedded Silverlight web resource.
When you add a Silverlight Web resource to a form you can select the Pass record object-type code and unique identifier as parameters option. You can also pass a custom parameter(data)as a string.

These values are passed to the Silverlight control as InitParameter.
We can then access these InitParameter from our SilverlightPage.xaml.cs, there are 7 parameters that we can access in this way:

// The unique identifier of the record
string recordGuid = App.Current.Host.InitParams["id"];

//The entity type code. For custom entities this can vary between organizations.
string type= App.Current.Host.InitParams["type"];

//The logical name of the entity.string logicName= App.Current.Host.InitParams["typename"];

//The name of the organizationstring orgName= App.Current.Host.InitParams["orgname"];

//The language code representing the user's language preference
string userLcid= App.Current.Host.InitParams["userlcid"];

//The language code representing the organization's base language
string orgLcid= App.Current.Host.InitParams["orglcid"];

 //The value of the text entered as a custom parameter
string data= App.Current.Host.InitParams["data"];

In a very recent post I talked about
how to retrieve different optionset labels for different languages, well that time I have only shown how to retrieve the labels. Now you can combine these two posts to get the language code you need to retrieve your customized labels.
This mechanism works fine only if the Silverlight web resource is embedded in an entity form, in order to be able to access crm contextual information from outside the form context, we need to configure the HTML page hosting the Silverlight control to access the Crm context by adding a reference to ClientGlobalContext.js and add the HTML page as a web resource as well.


  1. It is easy way to explain how passing data.Very Valuable and good and I like your design.Thank u.
    Ecommerce developer

  2. It's a greate copy past from sdk. Bravo