submitting a form with a webbrowser control as the target

G

Guest

I've come across a problem with the Webbrowser control that I am hoping some
of you folks might be able to help me with. FWIW, I am using VB.Net in Visual
Studio 2005.

On my company's website, we have a situation where a new window is opened
(in this case, we actually use ShowModalDialog to open the new window, but
using window.open seems to have the same problem).

The new window has a form on it. the target of that form is the original
page. Amazingly, this seems to work ok. Here is some sample code:

On the first page, we a bit of javascript like this...
<pre>

// set the windows's name
window.name = 'origPage';

// the function to open the window
function popupModal(url)
{
window.showModalDialog(url, window);
}

</pre>

then later on, there is a link to open the secondary page:
<pre>
<a href="javascript:popupModal('pageTwo.aspx');">Click here to open a new
modal page</a>
</pre>

On the secondary page (pageTwo.aspx), we have a form tag like this:
<pre>
<form name="form1" id="form1" action="Default.aspx" target="origPage"
method="post">
</pre>

So the Target attribute is pointing back to the original page. As I
mentioned before, this works ok when everything is done in a web browser.

The problem occurs when I try to use the web browser control instead of a
proper web browser.

The original page opens up fine, and the new window pops ok. When I try to
submit to the parent. Rather than the page in the webbrowser control being
reloaded, a new window opens up instead (with the same page as the one in the
webbrowser control).

I know that pageTwo can "talk" to the original one in the webbrowser
control. As a test a put a button pageTwo.aspx that looks like this:

<pre>
<input type="button" value="reload opener"
onclick="javascript:blush:pener.window.location.reload();" />
</pre>

The javascript works find and makes the original window reload.

I went a bit further, and added the following to the code behind of the form
hosting the webbrowser control.

<pre>
Me.WebBrowser1.Document.Window.Name = "origPage"
</pre>

(I put that in the Navigating even handler).

Still no luck.

Short of rewriting the html so that it doesn't pull this trick, is there
anything that I can do?

thanks,
Doug
 
J

Jeff

I assume you're hooking into the NewWindow3 event handling it in your
app, rather then letting it launch a new instance of IE?
jb
 
G

Guest

Hi Jeff,

Thanks for replying.

No, I am not using NewWindow3. That event does not seem to be available to
me. I see NewWindow, but not NewWindow3.

If it helps, I am using the webbrowser control from the Visual Studio 2005
toolbox.

Doug
 
J

Jeff

Hi Doug,

I'm not positive that NewWindow3 will help, but I bet it will.

Download this sample project and use it to browse to your test. If
this sample app can handle your test, then your answer lies in its
source code. If not, then I was wrong in guessing that the lack of a
NewWindow3 handler is causing your problem.

http://www.codeproject.com/csharp/ExtendedWebBrowser.asp

Good luck,
Jeff
 
J

Jeff

Using WebBrowser control w/o hooking into the underlying activeX
control makes lots of things unavailable to you, as I've learned in
the past few weeks.
 
G

Guest

Unfortunately, the Extended Web Browser application (the pre-compiled one)
from CodeProject didn't work either.

If I get a chance, I'll look through the source and see there is anything
that I can change to make it do what I want.

Or, maybe I'll report this as a bug to Microsoft. It might not help me, but
at least future generations will be able to do this. :)
 
J

Jeff

The Extended Web Browser is the most sophisticated use of the
WebBrowser control that I can find, yet it can't navigate the web site
I'm trying to incorporate into my C# app. Let me know if you find a
better example or a blob of code that solves your problem; perhaps it
will solve mine as well.

jb
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top