Silverlight and Javascript Interaction

I have a silverlight app page. An authentication key is built into my page in which the Silverlight application will have to fulfill all web service requests. Therefore, to download the Silverlight application, you must obtain the key and make the initial connection to the WCF service. The problem is that its very unpredictable loading of the first page or Silverlight, so I cannot use the onload = event pages, because sometimes silverlight is null, and I cannot use the silverlights initialization method, because sometimes the js function is still undefined - which I assume means that it loads the page from the cache, which loads SL, and only then parses JS.

Thank.

+5
source share
1 answer

You can force Silverlight interop to call the JS method and get its return value using the following:

// Returning a String
string stringValue = (string)HtmlPage.Window.Invoke("myJSMethod"); 

where myJSMethodreturns the built-in key. But if you insert the key anyway, why not just paste in <object><param>s?

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
  <param name="myKey" value="myKeyValue"/>
  ...
</object>
+1
source

All Articles