axWebBrowser1 and Setting Form Values in a .NET Windows Forms Application

By Robbe Morris
INSTANTLY dtSearch TERABYTES OF POPULAR DATA TYPES; hundreds of reviews, etc.!

Here is a sample for using the Web Browser Control in a .NET Windows Forms application and setting form values in the web page. Then, we'll submit the form.

public void SetDocumentElementsOnAForm()
{

object o = System.Reflection.Missing.Value;

this.axWebBrowser1.Navigate("http://www.mywebpage.com",ref o,ref o,ref o,ref o);

HTMLDocument doc = new HTMLDocumentClass();

doc = (HTMLDocument) this.axWebBrowser1.Document;

HTMLInputElement elem = (HTMLInputElement) doc.all.item("formelementname",0);

elem.value = "my value to set";

foreach (IHTMLFormElement _form in doc.forms)
{
_form.submit();
}

}


Submission Date:  9/24/2005 8:57:54 AM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

Popularity  (88 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP