Silverlight 2.0 plugin ID or not ID

My original problem was a call from HTMl via Jscript to the internals of a Silverlight plugin. My code fails I had huge problems to find the issue cause debugging doesn’t help and jScript doesnt support intellisense i a complete matter.

My checklist

1) Silverlight 1.0 uses a findname construct, Silverlight 2.0 the xaml class must expose a <Scriptable> member and it must be registered with RegisterScriptObject

HtmlPage.RegisterScriptableObject(

"hannespre", Me)

2) The Call by Jscript from a Silverlight event method like loaded, have a sender object as parameter. On that you can use getHost to get a instance of Silverlight host.

If you call without, like a hmtl button click, you have to find the the Silverlight plugin.

var slhost = document.getElementById("sl1");

3) ASPX or HTML. Silverlight projects in Visual Studio 2008 creates a additional web project. This have to test pages. A html and a aspx.

ASPX

<asp:Silverlight ID="SilverlightControl"

PluginBackground=Transparent

runat="server" HtmlAccess=Enabled

Source="~/ClientBin/SilverlightApplication1test.xap"

MinimumVersion="2.0.30812" Width="100%" Height="600"

/>

HTML

<

object data="data:application/x-silverlight," id="sl1"

type="application/x-silverlight-2" width="600px" height="400px">

<param name="source" value="ClientBin/SilverlightApplication1test.xap"/>

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

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

<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">

<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

</a>

</object>

The ID of the Silverlight Plugin is set with the ID attribute. There are different default values in ASPX and HTML (XAML1). If you miss the ID, Silverlight will work.

4) you can read the created plugin id during runtime

 Private Sub page8_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        HtmlPage.RegisterScriptableObject("hannespre", Me)
        label1.Text = HtmlPage.Plugin.Id
End Sub

 

5) From HTML following code access Plugin

function Button1_onclick()

{

var slhost = document.getElementById("sl1");

slhost.content.hannespre.interntext(

"geht");

}

6) take care on pressing F5 and starting debugging. Can start HTMl or ASPX page (and your code is in other page)

Published Sunday, August 24, 2008 8:05 AM by preishuber
Filed under: , ,

Comments

# funny wallpaper &raquo; Silverlight 2.0 plugin ID or not ID

Sunday, August 24, 2008 2:12 AM by funny wallpaper » Silverlight 2.0 plugin ID or not ID

Pingback from  funny wallpaper &raquo; Silverlight 2.0 plugin ID or not ID

Leave a Comment

(required) 
(required) 
(optional)
(required)