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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Hadi

    Blocking javascript popup from WebBrowser control.

    Hadi, Mar 23, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    899
    Gary Milton
    Mar 23, 2004
  2. zorhel
    Replies:
    2
    Views:
    1,126
    Kevin Yu [MSFT]
    Aug 24, 2004
  3. Guest

    Webbrowser Control and multiply document complete (Frame sites)

    Guest, Mar 1, 2007, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    749
    Guest
    Mar 1, 2007
  4. Jeff
    Replies:
    2
    Views:
    2,311
    Calvin Kwok
    Aug 13, 2010
  5. WebBrowser control and Javascript / Security

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

    WebBrowser Control, c# and javascript

    Alfonso Moreno, Jan 10, 2008, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    709
    Alfonso Moreno
    Jan 10, 2008
  7. John Brock

    How do I debug JavaScript in a WebBrowser control?

    John Brock, Sep 14, 2009, in forum: Microsoft Dot NET Framework Forms
    Replies:
    5
    Views:
    5,319
    Scott M.
    Sep 15, 2009
  8. Peter
    Replies:
    1
    Views:
    1,329
    Peter
    Mar 30, 2010
Loading...