Posts Tagged ‘DocumentText’

Setting the .NET WebBrowser Control’s DocumentText Property

Tuesday, June 30th, 2009

The .NET framework comes with a nice WebBrowser control, which is a wrapper around MS Internet Explorer.  The problem is that it can be rather quirky at times, and one of these times is when you try to set the DocumentText property from code.  It might work, and then again it might not.  It is quite difficult to pin down exactly when it does work and when it doesn’t, but the following bit of code seems to set it for me…

  wbMsg.AllowNavigation = False
        wbMsg.AllowNavigation = True


        If wbMsg.Document Is Nothing Then
            wbMsg.DocumentText = s
        Else
            wbMsg.Document.OpenNew(True)
            wbMsg.Document.Write(s)
        End If