GetElementById

  • Thread starter Thread starter Gidi
  • Start date Start date
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.
 
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.
 
Back
Top