Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HtmlElement.OuterHtml.Replace(­) fails with COM exception

HtmlElement.OuterHtml.Replace(­) fails with COM exception

Scheduled Pinned Locked Moved C#
csharpcomhtmldotnetvisual-studio
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cweeks78681
    wrote on last edited by
    #1

    I've tried asking this on microsoft.public.dotnet.languages.csharp, but I am getting no response. Maybe I'm getting lost in the traffic. So, let's try it here. 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: Default item I want to simply remove the the term 'selected' this way: elt.OuterHtml = elt.OuterHtml.Replace("selected",""); This results in OuterHtml being set to: 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. The MSDN documentation at http://tinyurl.com/edbln 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. 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?

    G 1 Reply Last reply
    0
    • C cweeks78681

      I've tried asking this on microsoft.public.dotnet.languages.csharp, but I am getting no response. Maybe I'm getting lost in the traffic. So, let's try it here. 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: Default item I want to simply remove the the term 'selected' this way: elt.OuterHtml = elt.OuterHtml.Replace("selected",""); This results in OuterHtml being set to: 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. The MSDN documentation at http://tinyurl.com/edbln 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. 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?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Perhaps you should start by mentioning what you are doing? Are you changing the page in a browser from another program? Do you have a browser component in your program that shows the page you are trying to change? Are you writing a client side component that is changing the page it is running in? --- b { font-weight: normal; }

      C 1 Reply Last reply
      0
      • G Guffa

        Perhaps you should start by mentioning what you are doing? Are you changing the page in a browser from another program? Do you have a browser component in your program that shows the page you are trying to change? Are you writing a client side component that is changing the page it is running in? --- b { font-weight: normal; }

        C Offline
        C Offline
        cweeks78681
        wrote on last edited by
        #3

        Ok, fair enough, I am automating navigation through a set of web pages by putting the NET 2.0 Webbrowser control on a dialog. When I get to the third page in the sequence I need to change the default item in a listbox on the web page to the item that I know in advance I want selected. I've been successful in using InvokeMember("Click") to click a button on a web page but I have not been able to "click" on an item in a list in order to select it.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups