user-avatar
Today is Monday
May 20, 2013

March 3, 2010

How to pass InitParameters to Silverlight in HTML object control

by Ashish Sehajpal — Categories: Development — Tags: , 1 Comment

There are three different ways in which we can pass parameters to Silverlight from the HTML side:

1. Pass parameters using the HTML object control.

This may be the case using pure HTML page to call silverlight control in it or may be the simple ASp.Net page as usual.

 <object width=”100%” height=”100%”>
   <param  name=”source”  value=”ClientBin/SomethingFunny.xap” />
   <!– you can pass InitParameters to it. Pass anything like EndPointURI, EndPointName or Even StartPage –>
   <param name=”InitParameters” value=”startPage=UnRegisteredLandingPage, EndPointURI=http://www.sehajpal.com/testservice.svc” />
 </object>

2. Using ASP.Net page to call silverlight control in it, we can easily pass parameters to it in anyway. One of the old tricks is to have an asp-literal control on the HTML side i.e. MarkUp side, and set its text to the desired HTML output fom code behind.

In the markup:
  <asp:Literal ID=”litParam” runat=”server” />

In the code behind:
  this.litParam.Text = String.Format(“<param name=\”ParamInitParameters\” value=\”{0}\” />”, sInitParms);

3. Using asp-silverlight control to host Silverlight application in an ASP.net website as usual. This is pretty neat approach in terms of playing around with parameters and properties of control hosting the Silverlight app.

In the markup:
  <asp:Silverlight ID=”SLControl” runat=”server” Width=”100%” Height=”100%” />
In the code behind:
   SLControl.InitParameters = “EndPointURI=” + endPointURI + “,EndPointName=commonservice, UserCredentials=” + CredentialString;

 

Hope it works for you in different scenarios.

1 Comment »

  1. Read More Here says:

    Yahoo News…

    This is really great news today….

© 2013 Sehajpal.com All rights reserved - Mobile View