Skip to content Skip to sidebar Skip to footer

Set Value Of A Textarea Inside A Webbrowser Control (c# / .net)

I'm looking to set the value of a TextArea using the .NET WebBrowser Control. I have been able to set the values of textboxes using the following code (replace 'username' with the

Solution 1:

Suppose you had the following HTML:

<html><body><textareaid='foo'>Testing</textarea></body></html>

You can set the text in the textarea like this:

HtmlElementtextArea= webBrowser1.Document.All["foo"];
if (textArea != null)
{
    textArea.InnerText = "This is a test";
}

Solution 2:

A couple of points just in case you haven't realised these:

  • GetElementById will only return a single item or null, it is not a collection.
  • index out of bounds errors will be thrown if you try and insert elements from one instance of the WebBrowser control into elements of another instance of the WebBrowser control.
  • The GetElementBy.. can be run straight from the WebBrowser.Document property so theres no need to access the All[] collection.

Post a Comment for "Set Value Of A Textarea Inside A Webbrowser Control (c# / .net)"