December 2017 : Online courses in ASP.NET MVC and Angular 4. Conducted by Bipin Joshi. Read more...
Registration for December 2017 batches of ASP.NET MVC / Core and Angular 4 online courses have already started. Conducted by Bipin Joshi. Book your seat today ! Click here for more details.

<%@ Page %>

Hosting Windows Custom Controls In Web Forms

Question

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?

Solution

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.

Advantages

  • 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.

Disadvantages

  • 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 a software consultant, an author and a yoga mentor having 22+ years of experience in software development. He also conducts online courses in ASP.NET MVC / Core and Design Patterns. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Meditation and Mindfulness to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 27 July 2002


Tags : ASP.NET Custom Controls Windows Forms Configuration Deployment