PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.

WebBrowser control, Document.MouseOver, and Javascript

 
 
Anderson Imes (Mary Kay, Inc.)
Guest
Posts: n/a
 
      15th May 2008
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect Popup fired by a webbrowser element to a second webbrowser Andre Rode Microsoft VB .NET 0 31st Mar 2008 10:27 AM
webbrowser control: how to capture event of mouse hovering over thelink or mouse click events in webbrowser only? P-GPS Microsoft VB .NET 1 15th Dec 2007 12:31 PM
How to Convert SHDocVw.WebBrowser to System.Windows.Forms.WebBrowser Qiang Microsoft C# .NET 2 22nd Sep 2006 03:33 PM
Create various instances of WebBrowser and store in a WebBrowser array, using VS.NET 2005 zorhel Microsoft Dot NET Framework Forms 2 24th Aug 2004 10:39 AM
Webbrowser control and javascript J?rn Microsoft C# .NET 0 12th Feb 2004 08:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 PM.