Export (0) Print
Expand All

HtmlDocument.GetElementById Method

Silverlight

Gets a single browser element.

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

[SecuritySafeCriticalAttribute]
public HtmlElement GetElementById(
	string id
)

Parameters

id
Type: System.String
A string identifier for a named browser element.

Return Value

Type: System.Windows.Browser.HtmlElement
A reference to a browser element.

ExceptionCondition
ArgumentException

id is an empty string.

ArgumentNullException

id is null.

InvalidOperationException

An unexpected error occurred.

If the specified HTML element cannot be found, this method returns null.

The following example uses the GetElementById method to get a reference to an HTML element named "Button123456". If this element does not exist, the variable named el is set to null and an error message is displayed.

HtmlDocument htmlDoc = HtmlPage.Document;
HtmlElement el = htmlDoc.GetElementById("Button123456");
If (el == null)
    HtmlPage.window.Alert("el is null");

Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft