<%@ 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
is a software consultant, trainer, author and yoga mentor having 22+ years of experience in software development. He also conducts online courses
on ASP.NET MVC, ASP.NET 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 Ajapa Yoga
to interested individuals. To know more about him click here
Get connected : Twitter Facebook