Skip to main content

Microsoft Silverlight

Answered Question Call JS from managed code in EB VB (Window.Invoke)RSS Feed

(0)

Kermit75
Kermit75

Member

Member

22 points

47 Posts

Call JS from managed code in EB VB (Window.Invoke)

I am trying to call JS from managed code using Expression Blend as decribed in the link below.
http://msdn.microsoft.com/en-us/library/cc221359(vs.95).aspx

I know the example is for VS2008, but should it not work in EB as well?

I get the errors:
* Name 'ControlChars' is not defined
* Namespace or type specified in the Imports 'System.Windows.Hosting' doesn't conain any public member or cannot be foiund. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

I have tried simplifying the "HtmlPage.Window.Invoke" as well as the JS method.
The project then builds, but the part of the page containing the Silverlight app gets blank, only the html button shows.
(And is not working)

WilcoB
WilcoB

Member

Member

720 points

137 Posts

Re: Call JS from managed code in EB VB (Window.Invoke)

Make sure you only call into HtmlPage properties/methods when HtmlPage.IsEnabled returns true. In Blend it should always return false.

- Wilco Bauwer (MSFT) / http://www.wilcob.com

Kermit75
Kermit75

Member

Member

22 points

47 Posts

Re: Call JS from managed code in EB VB (Window.Invoke)

 Hi, thanks for the reply.

Can you please clarify what you mean by "calling into"?

I have read this page on HtmlPage.IsEnabled, with no luck.
http://msdn.microsoft.com/en-us/library/system.windows.browser.htmlpage.isenabled(VS.95).aspx

When trying to get the value:

Dim value As Boolean
value = HtmlPage.IsEnabled
I ge an error message, regardles of where I have tried to put the code (even within a new sub).
Do I have to set the value or wait for the value to get set to true?
How do I do that?

rsmith2
rsmith2

Member

Member

16 points

3 Posts

Answered Question

Re: Call JS from managed code in EB VB (Window.Invoke)

You would set this in your web project. Enabled is the default setting, so this souldn't be an issue.     

<asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/SandBox.xap" MinimumVersion="2.0.30523" Width="100%" Height="100%" HtmlAccess="Enabled" />

This works for C#

System.Windows.Browser.HtmlPage.Window.Invoke("JavascriptFunction", "Parms1")

This works for vb.net

System.Windows.Browser.HtmlPage.Window.Eval("JavascriptFunction(Parms1)")

rsmith2
rsmith2

Member

Member

16 points

3 Posts

Re: Call JS from managed code in EB VB (Window.Invoke)

Sorry,

This should work with vb.net

HtmlPage.Window.CreateInstance("JavascriptFunction...", Parm1)

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities