Dynamics CRM 4 with Silverlight Part 1 – The IFRAME approach.


29/72010: Sorry but I am going to be dropping this series because my software focus has change to developing Windows Phone 7 applications. Maybe re visit this in the future (hopefully before CRM 5 is released Winking smile

Hi, this is part 1 of a series of posts giving an introduction to extending Microsoft Dynamics using Silverlight.

In this post I will outline how to add a custom Silverlight control to any of the entity forms.

For these articles I will be using Visual Studio 2010 Professional with All of the usual Silverlight (version 4) tools installed.

At Sequence the company where I work we make use of the eService accelerator this allows our customers to log cases via an extension to our web site.  For this series of posts I am going to create a new tab in the contact entity screen that will display details of the contacts log in details that are stored in a separate ASP.NET authentication database.

How it works

The CRM 4 entity forms allow administrators to customise forms in many different ways but the one way that makes things handy for us is the ability to add IFRAME elements into a form. We will use this customisation to display a Silverlight control inside the form.



Getting Started

Create a new Silverlight application as normal ensuring that you enable RIA services and create a test web project.

NOTE: In future when you will want to make this live you will need a server available that you can add the .Net framework 4 and host the web site or virtual directory.

Identifying the Entity

So that the Silverlight application knows what entity it is using it will need to be passed the Id of the entity that is being displayed in the entity form. To ensure that this works when you add an IFRAME customisation to an entity you will need to ensure that the I frame is passed the record ID and type:


This results in the following URL:


To get these values into my Silverlight application I have decided to use Silverlight parameters. To do this I first added the following code to the ASPX page that displays the application:

public string SilverlightParams







string sRes = string.Format("id={0},type={1},orgname={2},typename={3}",

            Request["id"], Request["type"], Request["orgname"], Request["typename"]);


   return sRes;



Then in the page mark-up I added the following to the params for the Silverlight application:

<param name="initParams" value="<% = SilverlightParams %>" />

So we get this:


<object data="data:application/x-silverlight-2," type="application/x-silverlight-2"

   width="100%" height="100%">


    <param name="source"   



    <param name="onError" value="onSilverlightError" />


    <param name="background" value="white" />


    <param name="minRuntimeVersion" value="4.0.50303.0" />


    <param name="autoUpgrade" value="true" />


    <param name="initParams" value="<% = SilverlightParams %>" />


    <a href=http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50303.0



   <img src=http://go.microsoft.com/fwlink/?LinkId=161376

       alt="Get Microsoft Silverlight" style="border-style:none"/>




</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

Making the App Know the entity Id

In the Silverlight application project I added the following to the App class code:


private Guid? m_ContactID = null;


public Guid? ContactID






        return m_ContactID;



In the Application_Startup method:


private void Application_Startup(object sender, StartupEventArgs e)



    if (!string.IsNullOrEmpty(e.InitParams["id"]))

        m_ContactID =

new Guid(e.InitParams["id"]);



    this.RootVisual = new MainPage();


We can now access the ContactID anywhere in the code like this:




Just checking

Here is a screenshot of a simple app in an I frame just to show it works:


In part 2 I will show how to hook this app up to the ASP.NET authentication database.


Tagged with: , ,
Posted in Dynamics CRM, Silverlight, VS2010, xRm
4 comments on “Dynamics CRM 4 with Silverlight Part 1 – The IFRAME approach.
  1. […] This post was mentioned on Twitter by mikehole. mikehole said: Me blogging some #Silverlight #CRM stuff: http://bit.ly/cknwbt #xRM […]

  2. LT says:

    Great post. I know you have moved on to new projects, but would you mind giving a brief synopsis on how you were planning to enable authentication?

    • mikehole says:


      It does appear that this is my most popular post so far so I will add a supplementary post in the next couple of days. By authentication I am referring to the management of the data within the eService portal. We used this and a Silverlight app to manage users (when they forget passwords, need removing etc).

      For now a quick pointer. This page shows you how to make the authentication service available to Silverlight:

      You could always create a WCF service, RIA Service or WCF Data Service that exposes the stored procs within the asp.net authentication database by making use of LINQ to SQL or the entity framework.
      You will have to make sure that the database that the authentication services use is pointing at the database that the eService portal is using.


  3. […] Dynamics CRM 4 with Silverlight Part 1 – The IFRAME approach. April 2010 3 comments 3 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: