Thursday, August 12, 2010

Step by Step - How to Host .Net Win Forms User Control in IE

If you ever wandered if its possible to use your Internet Explorer as hosting shell to your.NET Win Forms user control component - the answer is YES! and its easy ! In this post i will show how to do it step by step  :

Step I: Have a user control
Build up a simple user control that has a label , calendar and progress bar :

The user control i'm going to use
Step II : Move Binaries of the user control to the  IIS
Copy the binaries or configure the solution  project of the user control to output the binaries to the virtual directory of the IIS diretory  e.g.  C:\inetpub\wwwroot  .

Step III : Create web page and create instance of the user control
create HTML page with the following code and name it Host.html then save it in the virtual directory :

<html>
<head><title>Host My User Control</title><head>
<body>
<div id ="container">
<object id="MyUserControl" classid="http://localhost/MySmallControl.dll#MySmallControl.MyUserControl"</object>
</div>
</body>
</html>

where as;
MySmallControl.dll stands for the binary name
MySmallControl stands for the namespace of the project
MyUserControl stands for the class name of the user control


Step IV : Surf to the Host.html

open Internet Explorer and surf to  http://localhost/Host.html and you good to go !


The user control hosted in Internet Expolrer !

 
Related Topics i'm gonig to release soon:

  • How to interact between Javascript code and host user control C# code

  • How to give access to the host user control to the client's resources ,e.g. the Hard Disk

No comments:

Post a Comment