A
Anderson Imes (Mary Kay, Inc.)
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!
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!