Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I'm hoping someone can help. I have an html document with three frames, topFrame, middleFrame, and bottomFrame. I have the document loading in a webBrowser control in VB .net 2005. I have a button on my form and when the button is clicked, I want to add text to a text box in the bottom frame. All documentation on MSDN and what I have found online shows that the following simple code should work, but I get an error message when the button is clicked. Please help if you can. Here is the code I am trying to execute:

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

Dim hElement As HtmlElement = WebBrowser1.Document.GetElementById("parent.bottomFrame.document.getElementById('text')")

 

hElement.SetAttribute("value", "test")

 

End Sub

 

 

 

The error (NullReferenceException was Unhandled) that is displayed has to do with the .SetAttribute line. Thanks in advance. -gk

Posted

Yeah, the problem is the frame(s). I discovered this bit of code:

 

Dim variable As HtmlDocument

Dim variable2 as HtmlElement

variable = WebBrowser1.Document.Window.Frames(2).Document

variable2 = variable.GetElementById("element")

 

variable2.setAttribute("value", "test text")

 

This works with .invokeMember also...

 

So, this answers the question that I originally had and hopefully will pave the way for my using .invokeScript now that I know that I have to identify the frame where these actions are taking place.

 

If someone can provide some insight on how to obtain the highlighted text in an HTML page hosted in a WebBrowser control and add that text to a text box on the form (preferably without using javascript, but any solution will do), I would be grateful.

 

Thanks for looking.

 

-gk

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...