This is a migrated thread and some comments may be shown as answers.

Invoke Javascript from Silverlight

3 Answers 244 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Timothy Garton
Top achievements
Rank 1
Timothy Garton asked on 19 Feb 2010, 05:06 PM
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!





3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 24 Feb 2010, 06:18 PM
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.
0
Timothy Garton
Top achievements
Rank 1
answered on 24 Feb 2010, 07:00 PM
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. 



0
Tina Stancheva
Telerik team
answered on 01 Mar 2010, 03:31 PM
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.
Tags
HTMLPlaceHolder
Asked by
Timothy Garton
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Timothy Garton
Top achievements
Rank 1
Share this question
or