No path is too difficult. No destination is too far !
How to pass InitParameters to Silverlight in HTML object control
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.
| Print article | This entry was posted by Ashish Sehajpal on March 3, 2010 at 10:21 am, and is filed under Development. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |