Skip to main content

Microsoft Silverlight

Answered Question HtmlPage.Window.Invoke does not appear to work in VBRSS Feed

(0)

GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

HtmlPage.Window.Invoke does not appear to work in VB

i am thinking there is a problem with the HtmlPage.Window.Invoke in VB

 what works in C#, gets the following

An exception of type 'System.InvalidOperationException' occurred in System.Windows.Browser.dll but was not handled in user code

Additional information: [ScriptObject_InvokeFailed]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=8.0.30226.2&File=System.Windows.Browser.dll&Key=ScriptObject_InvokeFailed

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: HtmlPage.Window.Invoke does not appear to work in VB

Hello,

I just tested it. It's working for me.

Example:

Imports System.Windows.Browser

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        AddHandler MouseLeftButtonDown, AddressOf Click
    End Sub
    Public Sub Click(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        HtmlPage.Window.Eval("window.close();")
    End Sub
End Class

Hope it helps. 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

Agreed - the eval works - the invoke, which goes back to the Javascript isn't

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

GeordieJenner:
Agreed - the eval works - the invoke, which goes back to the Javascript isn't
 

Can you show me your code? It's working fine for me.

SilverlightApplication1VBTestPage.aspx

<%@ Page Language="VB" AutoEventWireup="true" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
    TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
    <title>Test Page For SilverlightApplication1VB</title>
    <script type="text/javascript">
     function foo(){
       alert("Foo() method is invoked.");
     }
    </script>
</head>
<body style="height:100%;margin:0;">
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  style="height:100%;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication1VB.xap" Version="2.0" Width="100%" Height="100%" />
        </div>
    </form>
</body>
</html>

Page.xaml.vb

Imports System.Windows.Browser

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        AddHandler MouseLeftButtonDown, AddressOf Click
    End Sub
    Public Sub Click(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        ''//HtmlPage.Window.Eval("window.close();")

        HtmlPage.Window.Invoke("foo", Nothing)
    End Sub
End Class

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

*****VB*****

Public Sub ExitProgram()

'HtmlPage.Window.Eval("window.close()")

'HtmlPage.Window.Invoke("Test")

HtmlPage.Window.Invoke("onCloseWindow", Nothing)

End Sub

**** HTML ****

<script type="text/javascript">

function onCloseWindow() {

window.close();

}

function onSilverlightError(sender, args) {

if (args.errorType == "InitializeError") {

var errorDiv = document.getElementById("errorLocation");

if (errorDiv != null)

errorDiv.innerHTML = args.errorType + "- " + args.errorMessage;

}

}

{

alert(1);

}

</script>

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

 It works for me. I tested with both HTML page or aspx page.

Example: 

SilverlightApplication1VBTestPage.aspx  (ASPX version)

 <%@ Page Language="VB" AutoEventWireup="true" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
    TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
    <title>Test Page For SilverlightApplication1VB</title>
    <script type="text/javascript">
     function onCloseWindow(){
       window.close();
     }
    </script>
</head>
<body style="height:100%;margin:0;">
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  style="height:100%;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication1VB.xap" Version="2.0" Width="100%" Height="100%" />
        </div>
    </form>
</body>
</html>

SilverlightApplication1VBTestPage.html (HTML Version) 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<!-- saved from url=(0014)about:internet -->
<head>
    <title>Silverlight Project Test Page </title>

    <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
    }
    </style>
   
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            if (args.errorType == "InitializeError")  {
                var errorDiv = document.getElementById("errorLocation");
                if (errorDiv != null)
                    errorDiv.innerHTML = args.errorType + "- " + args.errorMessage;
            }
        }
   
         function onCloseWindow(){
           window.close();
         }
   
    </script>
</head>

<body>
    <!-- Runtime errors from Silverlight will be displayed here.
    This will contain debugging information and should be removed or hidden when debugging is completed -->
    <div id='errorLocation' style="font-size: small;color: Gray;"></div>

    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%">
            <param name="source" value="ClientBin/SilverlightApplication1VB.xap"/>
            <param name="onerror" value="onSilverlightError" />
            <param name="background" value="white" />
           
            <a href="http://go.microsoft.com/fwlink/?LinkID=108182" 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>
</body>
</html>

Page.xaml.vb

Imports System.Windows.Browser

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        AddHandler MouseLeftButtonDown, AddressOf Click
    End Sub
    Public Sub Click(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        HtmlPage.Window.Invoke("onCloseWindow", Nothing)
    End Sub
End Class
 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

it works in aspx, i was only trying it in Html, which it still does not - thank you - but still no way to get rid of the dialog box  :O(

 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

GeordieJenner:
it works in aspx, i was only trying it in Html, which it still does not -
 

I showed you both aspx and HTML in my previous post.  "SilverlightApplication1VBTestPage.html (HTML Version) "

GeordieJenner:
but still no way to get rid of the dialog box  :O(
 

IMHO, I never like that idea... In fact, it is IE-only solution. I used to open a lot of tabs in my browsers and I never want any website to close my browser... I'm not sure why you want to do that.  

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

Re: Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

this is an application with passwords - if it fails, say 3 times, i want them kicked out

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Re: Re: Re: HtmlPage.Window.Invoke does not appear to work in VB

GeordieJenner:
this is an application with passwords - if it fails, say 3 times, i want them kicked out
 

Okay. But we are discussing about the fact whether HtmlPage.Window.Invoke is working fine in VB or not. 

Have you tested my code in my previous message? Is it working for you?  

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


GeordieJenner
GeordieJ...

Member

Member

102 points

61 Posts

Answered Question

Re: HtmlPage.Window.Invoke does not appear to work in VB

in aspx, not html, but yes, thank you

atkinart
atkinart

Member

Member

2 points

1 Posts

Re: HtmlPage.Window.Invoke does not appear to work in VB

 Hello, this method work in IE, but I use FireFox 3 and this method do not work. Please prompt me how I can solve this problem. Excuse my English :)

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities