WebBrowser control, Document.MouseOver, and Javascript

Discussion in 'Microsoft Dot NET Framework Forms' started by Anderson Imes (Mary Kay, Inc.), May 15, 2008.

  1. I've got a WinForm with a WebBrowser control on it. I've found that when I
    subscribe to the webBrowser.Document.MouseOver event, javascript that returns
    "false" to a "Click" event no longer stops a postback.

    An example would help. Here's the page the webbrowser control is navigating
    to (simplified, of course):

    <script runat="server">
    protected void asp_Button7066_Click(object sender, EventArgs e)
    {
    Response.Write("Yeah, we posted back!");
    }
    </script>

    <html>
    <body>
    <form id="form1" runat="server">
    <div>

    <asp:Button runat="server" id="asp_Button7066"
    OnClientClick="return confirm('are you sure?');"
    onclick="asp_Button7066_Click" Text="Wee"></asp:Button>

    </div>
    </form>
    </body>
    </html>


    Now, typically what you get with this is when you click "Wee" you see a
    confirm dialog. Clicking "Cancel" stops the postback and the server-side
    code with the Response.Write never gets a chance to fire.

    However, if I make the following modification to the WinForm that hosts the
    WebBrowser control, things change:


    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();

    this.webBrowser1.DocumentCompleted += new
    WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
    }

    void webBrowser1_DocumentCompleted(object sender,
    WebBrowserDocumentCompletedEventArgs e)
    {

    this.webBrowser1.Document.MouseOver += new
    HtmlElementEventHandler(Document_MouseOver);

    }

    void Document_MouseOver(object sender, HtmlElementEventArgs e)
    {
    //Even with no code here, I still am causing trouble
    }

    }

    Now, when I subscribe to Document.MouseOver, both "Ok" and "Cancel" cause a
    postback. It's as if the return value from the Confirm method is either
    always returning "true" or it's always being evaluated as true by the form.

    Anyone ever seen this? Do you know of a workaround? Thanks in advance for
    your help!
     
    Anderson Imes (Mary Kay, Inc.), May 15, 2008
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hadi

    Blocking javascript popup from WebBrowser control.

    Hadi, Mar 23, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    734
    Gary Milton
    Mar 23, 2004
  2. zorhel
    Replies:
    2
    Views:
    884
    Kevin Yu [MSFT]
    Aug 24, 2004
  3. Jeff
    Replies:
    2
    Views:
    1,632
    Calvin Kwok
    Aug 13, 2010
  4. WebBrowser control and Javascript / Security

    , Dec 14, 2007, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    454
  5. Alfonso Moreno

    WebBrowser Control, c# and javascript

    Alfonso Moreno, Jan 10, 2008, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    335
    Alfonso Moreno
    Jan 10, 2008
Loading...

Share This Page