1

I have a Silverlight application using C#, with 2 main functions that I want to make accessible from JavaScript functions. I have done the RegisterScriptableObject() in the class and set-up the [ScriptableMember] for the functions I want access to.

This the Silverlight object:

<div id="silverlightControlHost">
    <object id="silverlightControl" data="data:application/x-silverlight," type="application/x-silverlight-2" width="1024px" height="300px">
        <param name="source" value="DrawingWaveForm.xap"/>
        <param name="onerror" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="2.0.31005.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
            <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
        </a>
    </object>
    <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>

and these are my JavaScript functions:

    function Start()
    {
        var control = document.getElementById("silverlightControl");            
        control.Content.Page.Start();
    }

    function Stop()
    {
        var control = document.getElementById("silverlightControl");            
        control.Content.Page.Stop();
    } 

Can anyone tell me where I'm going wrong as it does not seem to work

2
  • i get the following error message: Error: uncaught exception: Error setting property on scriptable plugin object! [plugin exception: Object doesn't support this property or method]. Commented Feb 24, 2009 at 14:50
  • Would it be the same problem that was answered at this link? Javascript to Silverlight when Silverlight instanciated with object tag Commented Feb 23, 2010 at 15:42

4 Answers 4

2

As timheuer said, [Scriptable] on your Silverlight methods.

Call this in your class:

HtmlPage.RegisterScriptableObject("Page", this);  

Call the Silverlight methods marked as Scriptable from your javascript like this:

function CenterMap(latitude, longitude)
{
     var silvercontrol = document.getElementById("ctl00_cphMain_slControl");
     if (silvercontrol)
     silvercontrol.Content.Page.CenterOnCoordinates(latitude, longitude);
}

This page shows you this and how to do the reverse, calling javascript methods from Silverlight. It's a really nice model.

Sign up to request clarification or add additional context in comments.

1 Comment

Ignore the dirty hardcoded control id there :p a nice ends with works fine. var silverlightControl = $("[id $='slControl']");
1

You need to ensure your C# functions are marked as Scriptable. See http://silverlight.net/learn/learnvideo.aspx?video=65683 for some walk throughs on how to accomplish this.

1 Comment

I've done that, added [ScriptableMember] above both functions, but still get the message: Error: uncaught exception: Error setting property on scriptable plugin object! [plugin exception: Object doesn't support this property or method].
0

It's just a thought but do you perhaps need to make the methods public (they don't appear to be in your code)?

1 Comment

I've tried that and it didn't work, actually, it stopped my other functions working as well.
0

I was just hammering against this problem myself. The first js function works, but everything else throws this error. After tinkering around, I noticed that changing the underlying C# function that was working successfully was having no impact -- the browser was working with a cached version of the Silverlight control. Try clearing your browser's cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.