views:

376

answers:

2

Hi. :-)

I've used an object tag to load my Silverlight control because I want to be able to input html into a Sharepoint page using the Rich Text Editor. It looks like this:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" id="SilverlightObject"
    width="850" height="600">
   <param name="source" value="ClientBin/LabsSurvey.xap"/>
   <param name="onError" value="onSilverlightError" />
   <param name="minRuntimeVersion" value="3.0.40624.0" />
   <param name="autoUpgrade" value="true" />
   <img src="ClientBin/InstallSilverlightLabsBanner.jpg" alt="Please Install Silverlight" />
   <br />
   <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration:none">
    <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
   </a>

    </object>

I've use the Javascript bridge in other Silverlight apps, and it works great for two-way communication between the web page and the Silverlight control.

BUT - it seems that in order for this to work, I have to instanciate my Silverlight control using the .NET Silverlight control.

I can not get a javascript call to a method within my Silverlight control to work when I've used the object tag. I set it up exactly the same way as in my other apps where it does work - the only difference is that the control was not embedded the same way in the html.

Does anyone have any tips for me?

Thanks!

A: 

You might want to check out this thread:

http://stackoverflow.com/questions/2051092/how-to-call-javascript-function-on-a-silverlight-3-object

I had problems as well and got it all working using the object tag.

Kelsey
Thanks for the link, I appreciate your help. But these things suggested in the other thread are already part of my application. Still it didn't work for me. I had to get my app working and so found another way to carry out the communications.
BPerreault
+1  A: 

It's also key to include the windowless parameter in your object definition in addition to the information called out in the answer from Kelsey. Without windowless=true, the call to Content will always return undefined....

Sample object definition:

    <div id="silverlightControlHost">
    <object id="silverlightObject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
      <param name="source" value="ClientBin/LabsCharts.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="windowless" value="true" />
      <param name="minRuntimeVersion" value="3.0.40624.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

VB.Net class to register scriptable object:

Imports System.Windows.Browser

_ Partial Public Class MainPage Inherits UserControl

Public Sub New()
    ' Required to initialize variables
    InitializeComponent()
    AddHandler Loaded, AddressOf MainPage_Loaded
End Sub

Protected Sub MainPage_Loaded(ByVal sender As Object, ByVal e As EventArgs)
    HtmlPage.RegisterScriptableObject("MainPage", Me) 'not working!

    Dim so As ScriptObject = TryCast(HtmlPage.Window.Eval("charts"), ScriptObject)
    so.Invoke("registerSilverlight")
End Sub

Public Sub SayHi() MessageBox.Show("HI!!!!!") End Sub

End Class

And the javascript function, registerSilverlight

var charts = {
registerSilverlight: function() {

    var func = document.getElementById('silverlightObject');
    var content1 = func.Content;
    content1.MainPage.SayHi();


}

}

BPerreault