469,609 Members | 1,160 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

HtmlElement.OuterHtml.Replace() fails with COM exception

Dev env: VS 2005 C# Express, .Net Framework 2.0

I am trying to programmatically select an item in a listbox on a web
page. The first thing I do is go through and de-select any selected
items. The OuterHtml field of a selected element in the listbox looks
something like this:

<OPTION value=* selected>Default item</OPTION>

I want to simply remove the the term 'selected' this way:

elt.OuterHtml = elt.OuterHtml.Replace("selected","");

This results in OuterHtml being set to:

<OPTION value=* selected></OPTION>

Notice: 1) the 'selected' term is untouched, 2) the visible text has
been removed.

After the assignment I can see in the debugger that one of the members
of the HtmlElement object (OffsetParent, I think) has a string
indicating some kind of COM Interop services exception.

Is it possible to change the HTML in a web page? Am I going about it
the wrong way? Is there some kind of initialization or setup call I am
supposed to make? Is it just a bug in .NET 2.0?

Apr 25 '06 #1
1 3358
The MSDN documentation at


does contain this warning:

"If you assign a new value to OuterHtml, the current element reference
will become invalid; it will not reflect the name, properties and child
content of the HTML you have just assigned."

but I don't really understand what that means.

Apr 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jason Keirstead | last post: by
4 posts views Thread by harry | last post: by
1 post views Thread by Richard | last post: by
1 post views Thread by Christopher Benson-Manica | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.