Tuesday, July 7, 2009

2 way communication between embedded windows user control into Internet Explorer


My original task it was: Create a .net wrapper class for an existent native C++ code and expose to web page as like in Active X but in .Net and set up an environment in what are able to communicate the web page with native code and vice-verso. This task isn't finished yet, but I have found a solution for intercommunication between client side web page an a .net user control. In this article I will show how to place an C# user control on the IE web page (client side) and the user control how can communicate with web page and back. In this way can be built rich client side application in .Net.


In the IE can we embed the user control with tag. The user control will able to fire an event which will catch by javascript on the web page and the javascript can call user control code. To the user control need to grant privileges with caspol.exe. Instead to add full trust to user control I will give for the whole site(can be a security leak in some cases) because from the .net 2.0 there is no .net administrator and global assembly cache if the user don't want to download the platform SDK, jut the framwork.

Using the code

I have installed Visual studio 2008 with .Net framework 3.5, and without platform SDK, so I haven't gacutil.exe to add to cache my assembly.

Start the Visual Studio 2008 with C# installed and press File -> New Project. On the left side click on the C#, now on the right side select the WindowsFormsControlLibrary. I have renamed my WindowsFormsControlLibrary1 name to UserControl3 (to make a different name from other work), that change the default namespace from WindowsFormsControlLibrary1 to UserControl3 -nothing else. Now there are 2 samples on the web which is almost working:

See full detail: http://www.codeproject.com/KB/user-controls/user_control_on_IE.aspx

No comments: