<%@ Page %>

Hosting Windows Custom Controls In Web Forms


This article and code sample is intended to solve following frequently asked question:

I want to display a FileOpen dialog box in my ASP.NET web form. When user selects a file the file should be opened with an associated application installed on the client machine. I do not want to use ActiveX controls. Is there any other way to do that? How?


The above problem can be solved by creating a custom windows control and hosting it in a ASP.NET web form. The <OBJECT> tag allows you to load and refer to your windows control on the client side. You need to adjust .NET security policy on the client machine to trust the web site sending the control. This can be done using Control Panel > Administrative Tools > Microsoft .NET Framework Configuration option. Right click on the Runtime Security Policy and the select Adjust security from the shortcut menu. The adjust security wizard will start. Using the wizard increase trust level for trusted sites zones to Full Trust. You also need to go to Tools > Options menu of IE and add the site url under trusted web sites zone.


  • You get custom functionality that is otherwise not available with web server controls
  • Windows forms custom controls can be hosted more safely in IE as compared to traditional ActiveX controls.


  • This solution will work only in Internet Explorer
  • The control may take time to download in the browser
  • You need to alter security policy of your machine to trust the site that is sending the control
  • You need .NET framework installed on client machine

Running the sample code

  • Create a new windows custom control project in VS.NET
  • Add FileOpenDialogInWebForm.vb to it and compile
  • Create a new ASP.NET web project in VS.NET named WinControlInWebClient
  • Add WebForm1.aspx and WebForm1.aspx.vb to the project
  • Copy custom control DLL in BIN directory
  • Run the web form

Bipin Joshi is an independent software consultant and trainer by profession specializing in Microsoft web development technologies. Having embraced the Yoga way of life he is also a meditation teacher and spiritual guide to his students. He is a prolific author and writes regularly about software development and yoga on his websites. He is programming, meditating, writing, and teaching for over 27 years. To know more about his ASP.NET online courses go here. More details about his Kriya and Meditation online course are available here.

Posted On : 27 July 2002

Tags : ASP.NET Custom Controls Windows Forms Configuration Deployment