Hosting .NET control in IE: Communication with parent page RRS feed

  • Question

  • Hello everybody,

    I am trying to find a way to add in low level communication between my .NET usercontrol and the Internet Explorer window that my control is hosted in. The best method i have found so far is using a implementation of the code sample found  in this newsgroup thread (post before last): http://www.dotnet247.com/247reference/msgs/41/207420.aspx. My problem is that GetClientSite always returns null and i am not sure why. I would take a guess that the .NET usercontrol has not been sited within IE but why is this and how can i make the usercontrol site itself? Within my .NET control I have selected "Register for COM interop" and i have changed ComVisible to true within AssemblyInfo.cs. Would i have to do anything else to get the ClientSite from IE?

    Thanks in advance.

    Tuesday, May 13, 2008 7:49 AM


  • After lots of searching I have come accross another method using SHDocVw that seems to work. I found this posted at http://www.pcreview.co.uk/forums/thread-1413174.php. The only modification I have made is the Process.GetCurrentProcess call rather than generating a new process.

    Code Snippet
    Process m_Proc = Process.GetCurrentProcess();
    InternetExplorer m_IEBrowser = null;
    ShellWindows m_IEFoundBrowsers = new ShellWindowsClass();
    foreach (InternetExplorer Browser in m_IEFoundBrowsers)
         if (Browser.HWND == (int)m_Proc.MainWindowHandle)
              m_IEBrowser = Browser;


    I hope the above snippet helps other people that attempt to do this. There are quite a few posts showing other methods that no longer seem to work. Whereas the above approach is quite a simple method and works really well.

    Tuesday, May 13, 2008 10:11 AM