Introduction
Making simpler Controls in Windows Forms and exposing them as ActiveX Controls has never been easier before .NET. But the catch is that at least the .NET Runtime must be available on the client machine before the OBJECT tag can be manipulated via JavaScript or there would be runtime errors in the rendered page.
Detecting .NET Runtime
Fortunately, when you install .NET SDK/Runtime, it plugs in to the Client Machine Web Browser, so that the
UserAgent Field now also contains a string to reflect CLR availability for scripts. The
UserAgent Field now also contains Build Version. But the Revision is not being carried into the
UserAgent, as the JavaScript shows.
The Method
Just use the following simple JavaScript to detect whether you have .NET CLR installed for use from with Internet Explorer or not.
if ((navigator.userAgent.indexOf(".NET CLR")>-1))
alert ("CLR available " +navigator.userAgent);
else
alert(".NET SDK/Runtime is not available for us from within " + <BR> "your web browser or your web browser is not supported." + <BR> " Please check with http://msdn.microsoft.com/net/ for " + <BR> "appropriate .NET runtime for your machine.");
How To Use
Using a simple Windows Form Control as ActiveX Controls in WebPages is quite simple. Make a simple C#/VB.NET Class Library. Build the application. Copy the DLL from the bin folder into an appropriate WebRoot. Now you can refer this Component from simple
OBJECT tag variant.
<object id="DeepakControl" name="DeepakControl" <BR> classid="DeepakAlert.Dll#LavanyaDeepak.DeepakAlert" VIEWASTEXT <BR> width="0" height="0">
</object>
Now you can refer the DLL and its Public Methods/Properties by simple JavaScript Assignments. All unhandled exceptions will be shown as Internet Explorer MessageBoxes.
Conclusion
I hope the above article would really be very useful for many developers worldwide in making simple and elegant ActiveX Controls using C#/Windows Forms and exposing them using OBJECT tag.