Editare

Partajați prin


HtmlElementCollection.GetElementsByName(String) Method

Definition

Gets a collection of elements by their name.

public:
 System::Windows::Forms::HtmlElementCollection ^ GetElementsByName(System::String ^ name);
public System.Windows.Forms.HtmlElementCollection GetElementsByName (string name);
member this.GetElementsByName : string -> System.Windows.Forms.HtmlElementCollection
Public Function GetElementsByName (name As String) As HtmlElementCollection

Parameters

name
String

The name or ID of the element.

Returns

An HtmlElementCollection containing the elements whose Name property match name.

Examples

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"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}
Private Sub SubmitForm(ByVal FormName As String)
    Dim Elems As HtmlElementCollection
    Dim Elem As HtmlElement

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Elems = .All.GetElementsByName(FormName)
            If (Not Elems Is Nothing And Elems.Count > 0) Then
                Elem = Elems(0)
                If (Elem.TagName.Equals("FORM")) Then
                    Elem.InvokeMember("Submit")
                End If
            End If
        End With
    End If
End Sub

Remarks

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

Applies to