GetElementById

G

Gidi

Hi,

I'm using a webBrowser object to load an html file and i want to replace the
some text after i loaded the file.

this is the code i'm using:
HtmlElement h = webBrowser1.Document.GetElementById("str1");
h.InnerText = m_name;
h = webBrowser1.Document.GetElementById("str2");
h.InnerText = m_id;
webBrowser1.Print();

this is the part in the htm i want to replace:
<span dir=LTR
style='font-size:14.0pt'>TEXT1</span>

when i try to find the element by ID i get null, my guess is that becuase i
don't have the id in my html...( :) ), i tried to add input it tag but it
didn't work, so what am i doing wrong?

Thanks,
Gidi.
 
M

Martin Honnen

Gidi said:
this is the code i'm using:
HtmlElement h = webBrowser1.Document.GetElementById("str1");
h.InnerText = m_name;
h = webBrowser1.Document.GetElementById("str2");
h.InnerText = m_id;
webBrowser1.Print();

this is the part in the htm i want to replace:
<span dir=LTR
style='font-size:14.0pt'>TEXT1</span>

when i try to find the element by ID i get null, my guess is that becuase i
don't have the id in my html...( :) ), i tried to add input it tag but it
didn't work, so what am i doing wrong?

Well if an element does not have an id attribute then it can't be
accessed using GetElementById, that should be obvious. There are other
ways to find elements, for instance using
webBrowser1.Document.GetElementsByTagName("span")
you could find all 'span' elements in the document, you can then iterate
through them to look for the one you want to change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top