Invoke Javascript from Silverlight

4 posts, 0 answers
  1. Timothy Garton
    Timothy Garton avatar
    14 posts
    Member since:
    Sep 2009

    Posted 19 Feb 2010 Link to this post

    Hi

    I have an HTMLPlaceHolder in my silverlight application and I was wondering if there is a way to use HtmlPage.Window.Invoke(function, parameters); to call the javascript functions inside of it.

    I am currently using the Eval function, such as on this page
    http://www.telerik.com/support/kb/silverlight/htmlplaceholder/htmlplaceholder-javascript.aspx

    and I want to use Invoke instead. Is there any way?

    Thanks!





  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 24 Feb 2010 Link to this post

    Hello Michael Stewart,

    I have prepared a project that illustrates how you can use the Invoke function instead of the Eval when calling a JavaScript function in an external HTML page, displayed by the RadHtmlPlaceHolder.

    The example shows how to call the OpenPdf() JavaScript function from the managed code as well as how to call the getName() method from the JavaScript function.

    I hope this helps.

    Please let us know if you need more info.

    Sincerely yours,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Timothy Garton
    Timothy Garton avatar
    14 posts
    Member since:
    Sep 2009

    Posted 24 Feb 2010 Link to this post

    Thanks.  I was able to get this to run in IE, but in Firefox I get the following error.  This is the same error we have been getting on our project as well, we just never noticed it was limited to IE. 

    uncaught exception: System.InvalidOperationException: Failed to Invoke: OpenPdf.
       at System.Windows.Browser.ManagedObjectInfo.Invoke(ManagedObject obj, InvokeType invokeType, String memberName, ScriptParam[] args)
       at System.Windows.Browser.ManagedObject.Invoke(InvokeType invokeType, Int32 memberID, ScriptParam[] args)
       at System.Windows.Hosting.ScriptingInterface.InvokeScriptableMember(ManagedObject obj, InvokeType invokeType, Int32 memberID, ScriptParam[] args, ScriptParam& pResult)
       at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)

    Line 0

    I have not been able to find out the reason for this.  Most of our customers are using IE, but in order to be able to do some debugging of our JavaScript we use FireBug in Firefox, so it would be great if we had a way to get around this error. 



  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 01 Mar 2010 Link to this post

    Hello Michael Stewart,

    It seems that there is a common problem with the usage of the document.all statement in Mozilla.

    Still, there is a known workaround the issue. Please change the javascript script like this:

    function OpenPdf() {

               var silverlightApplication = parent.GetSilverlightApplication();
               src = silverlightApplication.Content.MySilverlightPage.getName();

               if (document.all && document.all.MyIFrame != null) {
                     document.all.MyIFrame.src = src;
                    }
               else if (document.getElementById("MyIFrame")){
                        document.getElementById("MyIFrame").src = src;
                       }

            }

    This should solve the problem.

    I am attaching the modified example if you want to take a look.

    Please let us know if you need more info.

    All the best,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top