views:

16

answers:

1

How can I get the text in a text area within a form in browser control? Is there a method?

A: 

(NOTE: I'm assuming that you mean the WebBrowser control.)

You need to walk the DOM of the document in the control. You'll have to start loading the control and then query the DOM after it's loaded. Here is an example:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf DocumentCompletedHandler)
        WebBrowser1.Navigate("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea")

    End Sub

    Private Sub DocumentCompletedHandler(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        ' Walk the DOM of the document (any time needed after the document has been loaded)
        Dim element As HtmlElement

        For Each element In WebBrowser1.Document.GetElementsByTagName("textarea")
            ' Limit our text area to the one with class="code_input".
            ' You can change this to any other attribute that makes sense:
            If element.GetAttribute("className") = "code_input" Then
                Console.WriteLine(element.InnerText)
            End If
        Next
    End Sub
End Class
steinar