Hi
Based on my research, it seems that when we click the submit button, the
webbrowser will try to redirect to another URL(the action section), then
the webbrowser will try to dispose the form, htmlelement etc. But now our
programm is keeping the reference to the form which will prevent the form
to be dispose, while if we dispose it too early the event will not fire,
because the instance has been disposed.
So as a workaround I think we can add a reference to the submit button,
after we click the button but before the submit raised, we will fire a
button click event,in the event handler, we need to release the com
reference to the form and the button, so that the following submit process
which will redirect to another url will go through.
mshtml.HTMLFormElement theForm=null;
mshtml.HTMLButtonElement btn=null;
private void BrowserReady(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent evt)
{
if (sender != axWebBrowser1)
{
return;
}
axWebBrowser1.DocumentComplete -= new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.BrowserReady)
;
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)
axWebBrowser1.Document;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string eol = System.Environment.NewLine;
sb.Append("<HTML>" + eol + "<BODY>" + eol + "<H1>Header</H1>");
sb.Append("<table border=\"1\" width=\"100%\">" + eol);
// header
sb.Append("<tr>" + eol);
sb.Append("<td width=\"20%\" bgcolor=\"#C0C0C0\" >Property</td>"
+ eol);
sb.Append("<td width=\"80%\" bgcolor=\"#C0C0C0\" >Value</td>" +
eol);
sb.Append("</tr>" + eol);
// BI Path
sb.Append("<tr>" + eol);
sb.Append("<td width=\"20%\">Name</td>" + eol);
sb.Append("<td width=\"80%\">Static@nospam.nospam</td>" + eol);
sb.Append("</tr>" + eol);
sb.Append("</table>" + eol);
sb.Append("<br>" + eol);
sb.Append("<hr>" + eol);
sb.Append("<P><INPUT id=button1 type=button value=Button
name=button1></P>" + eol);
sb.Append("<form method=\"POST\" name=\"MyForm\" action=\"about:blank\">"
+ eol);
sb.Append("<p><input type=\"submit\" value=\"Submit\" name=\"B1\"></p>" +
eol);
sb.Append("<p><input type=\"text\" name=\"T1\" value=\"some text\"
size=\"20\"></p>" + eol);
sb.Append("</form>" + eol);
sb.Append("<hr>" + eol);
sb.Append("</BODY>" + eol +"</HTML>" + eol);
doc.write(sb.ToString());
doc.writeln(new object[]{"<br>"});
doc.close();
mshtml.IHTMLElementCollection eles =
(mshtml.IHTMLElementCollection) doc.all;
btn = (mshtml.HTMLButtonElement)
eles.item("B1", 0);
((mshtml.HTMLButtonElementEvents_Event)btn).onclick +=new
mshtml.HTMLButtonElementEvents_onclickEventHandler(Form1_onclick);//Add a
button click event handler.
theForm = (mshtml.HTMLFormElement)
eles.item("MyForm", 0);
((mshtml.HTMLFormElementEvents2_Event) theForm).ondblclick +=
new
mshtml.HTMLFormElementEvents2_ondblclickEventHandler(this.catchDblClick);
System.Runtime.InteropServices.Marshal.ReleaseComObject(eles);
eles = null;
}
private bool Form1_onclick()
{
Console.WriteLine("Button clicked");
System.Runtime.InteropServices.Marshal.ReleaseComObject(btn);//Release the
button com reference
btn = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(theForm);//Release
the form com reference.
theForm = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
return true;
}
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.