HtmlElementCollection.GetElementsByName Method (String)


Gets a collection of elements by their name.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElementCollection GetElementsByName(
	string name


Type: System.String

The name or ID of the element.

Return Value

Type: System.Windows.Forms.HtmlElementCollection

An HtmlElementCollection containing the elements whose Name property match name.

While the Id property of an HtmlElement must be unique, multiple elements can use the same Name property.

The following code example finds a FORM object using its name, and submits its data to the server programmatically. The code example requires that your application hosts a WebBrowser control named webBrowser1.

private void SubmitForm(String formName)
	HtmlElementCollection elems = null;
	HtmlElement elem = null;

	if (webBrowser1.Document != null)
		HtmlDocument doc = webBrowser1.Document;
              elems = doc.All.GetElementsByName(formName);
              if (elems != null && elems.Count > 0) 
                  elem = elems[0];
                  if (elem.TagName.Equals("FORM"))

.NET Framework
Available since 2.0
Return to top