How do you use a .NET object in IE?

  • Thread starter Thread starter Wells Caughey
  • Start date Start date
W

Wells Caughey

Hello everyone,

I am trying to load and use a .NET object in Web Page as described by
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpcondeployingco
mmonlanguageruntimeapplicationusingie55.htm

As a summary it says to use the Object tag with an classId similar to
classId=http://mydomain/path/myAssembly.dll#classname. Well, I've done this
and it appears that assembly has been downloaded and is being run. My
problem is, now that it is running locally in IE, how do I get the object to
do anything? I would like the object to manipulate the DHTML DOM but I
can't seem to find any documentation on this?

Any help (including what newsgroups might be more appropriate) would be
greatly appreciated.

Thanks,
Wells
 
Thanks for your reply, Eliahu.

I'm not really concerned with the load-time performace increase I could get
by putting my assembly in the GAC. In fact, I would have to use an
installer program to install my assembly in the GAC, which is undesirable
because I don't want the user to have to involved in that.

The problem that I am having is, assuming that my Assembly is already on the
target client machine, and even loaded into memory in IE, what interfaces
and/or classes do I need to implement in my classes in that assembly in
order to allow those classes to interact with the DHTML DOM?

Wells

Eliahu Baker said:
I would propose registering in GAC or putting assembly into same dir with
iexplore.exe
 
Hi Wells,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to implement in
your classes in that assembly in order to allow those classes to interact
with the DHTML DOM. If there is any misunderstanding, please feel free to
let me know.

As far as I know, to access the DOM programmatically, you import both the
Web browser component and references to the methods, properties, and events
of the DOM into your C# project. You direct the Web browser to a URL by
calling its Navigate method, and you must then wait for the documentation
complete event. You obtain the document by casting the Web browser Document
property to an IHTMLDocument2 interface object. You can query this object
for its collections, such as its link or image collections, which are
returned as IHTMLElementCollection objects.

Here is an article for a walkthrough. HTH.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechar
t/html/vsgrfWalkthroughAccessingDHTMLDOMFromC.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
This is very interesting!! I would love to do this for the project I'm
working on (.Net control running in IE). Are you able to either point me to
an example or perhaps send/paste some sample .net code for the object that
will be hosted in IE?

Thanks!
-Mike
 
Hi Kevin,

This is half of what I want to do. Let me give you some additional
background on what I am doing. I am building a website that is the primary
user interface for my company's products. To give our clients the best
possible experience using our product, we have enriched each of the website
pages with client-side script in form of DHTML Behaviors. These scripts
perform various tasks such as building HTML Tables, calling webservices, and
posting back collected data via XMLHTTP. So far, the site with the script
works fairly well, but the script is extremely slow and cumbersome to work
with. There are also memory leak issues caused by they way the scripting
engine interacts with MSHTML. So while using script is possible, it is not
very desirable.

What I want to do, is to replace some (if not all) of the script with a .NET
component. I want this component to be created and hosted by IE through the
<object> tag in such a way that I do not have to request .NET permissions
other than those granted by default to components running in the "Internet
Zone." Once the component represented by the <object> tag is loaded, I'm
going to want it to make changes to its containing HTML DOM in order to
render HTML tables and do all those things I do in script now.

So far I have written a test component and loaded it into a test HTML
document, but I don't know how to get a reference to the containing
document.

Your help in the matter is very appreciated.
Wells
 
Hi Mike,

I am still in the research phase so I don't really have any code that would
be interesting. In all honesty, I don't even know if this is possible, but
if I find anything out, I'll be sure to post back into this same thread.

Wells
 
Hi Wells,

Since you can load the text HTML document, I think you can get the path or
URL for the document. For example, in JavaScript we can use window.location
to get the URL and pass it to methods in the assembly as a parameter. Then
you just load the document with Web browser component and let it parse to
IHTMLDocument2 interface object for you. This is the simplest way as far as
I know.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Ok I think I understand what you are saying: Create an MSHTML sandwich. The
outer MSHTML instance loads a simple document that only contains the
<object> that points to my custom component. In turn, my custom component
hosts a MSHTML control and sets its location to the real HTML document. At
the very least, this will give me a good starting point.

Thanks for the help,
Wells
 
Back
Top