Welcome Guest Search | Active Topics | Sign In | Register

WebView1.JSDialog triggers two events Options
kevin_ll
Posted: Tuesday, September 6, 2016 12:11:12 PM
Rank: Member
Groups: Member

Joined: 12/10/2015
Posts: 17
WebView1.JSDialog triggers two events
for example
Code: Visual Basic.NET
Private Sub WebView1_JSDialog(sender As Object, e As EO.WebBrowser.JSDialogEventArgs) Handles WebView1.JSDialog
        If e.DialogType = EO.WebBrowser.JSDialogType.Alert Then
            MessageBox.Show(e.MessageText, e.OriginUrl, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            e.Cancel()
        ElseIf e.DialogType = EO.WebBrowser.JSDialogType.Confirm Then
            If MessageBox.Show(e.MessageText, e.OriginUrl, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = DialogResult.OK Then
                e.OK()
            Else
                e.Cancel()
            End If
        End If
    End Sub


Code: HTML/ASPX
<html>
<head>
<script>
     alert("abc");
</script>
</head>
</body>

Why triggers the two alert?
eo_support
Posted: Tuesday, September 6, 2016 12:31:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

We tested your code here and it works fine. You may want to check whether you have hooked up your event handler twice.

Thanks!
kevin_ll
Posted: Tuesday, September 6, 2016 12:45:07 PM
Rank: Member
Groups: Member

Joined: 12/10/2015
Posts: 17
This phenomenon does not appear in the form, but the reference to the class will be like this

Code: Visual Basic.NET
Public Class abc

        Private WithEvents WebView1 As EO.WebBrowser.WebView

        Public Sub New(ByRef vEOWebView As EO.WebBrowser.WebView)
            WebView1 = vEOWebView
        End Sub

        Private Sub WebView1_JSDialog(sender As Object, e As EO.WebBrowser.JSDialogEventArgs) Handles WebView1.JSDialog
            If e.DialogType = EO.WebBrowser.JSDialogType.Alert Then
                MessageBox.Show(e.MessageText, e.OriginUrl, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                e.Cancel()
            ElseIf e.DialogType = EO.WebBrowser.JSDialogType.Confirm Then
                If MessageBox.Show(e.MessageText, e.OriginUrl, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = DialogResult.OK Then
                    e.OK()
                Else
                    e.Cancel()
                End If
            End If
        End Sub
    End Class


    Public Class Form1 'Main Form
    Pirvate aaa As abc
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            aaa = New abc(WebView1)
        End Sub
    End Class
eo_support
Posted: Tuesday, September 6, 2016 1:07:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

This is almost certainly because the event handler has been hooked up more than once. You can try to removes Handles WebView1.JSDialog and use AddHandler to epxlicitly hook up the event handler like in our sample code. The "Handles" syntax is prone to duplicate hookup problems, particularly with dynamically created controls.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.