Silverlight Feeds - All your Silverlight feeds in one place.

Sponsors

Sunday, August 24, 2008

Silverlight 2.0 plugin ID or not ID

by preishuber via Hannes Preishuber on 8/24/2008 6:05:26 AM

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)

email it!bookmark it!digg it!

Original Post: Silverlight 2.0 plugin ID or not ID

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us