ActiveX Controls Support CustomizationProgramInterface. In this way, events and attributes of controls can be accessed externally, and the interoperability between. NET platform and COM is used. The purpose of modifying project properties is to register the. Net control as an ActiveX control. In this way, you can treat this control as an ActiveX control. You can use JS and vbs to call it (install. NET Framework on the client ). Web developers can automatically operate on their web pages, which is equivalent to the functions of common desktop applications. ActiveX controls are run as local users, so they can break through. Net security restrictions.
Use C # To compile ActiveX classes
First, write an interface asignatures that contains all method property definitions. You can access these methods or attributes by executing Javascript in your browser. All the Members in the interface are abstract and open. ActiveX Aclass inherits from this interface. In ActiveX class, we must name its classinterfacetype autodal (* Note: indicates that a dual interface is automatically generated for the class and made public to com. Generate type information for this type of interface and publish it in the class library ). Generally, autodual is not recommended because it has version restrictions. We use it for the purpose of learning. In the class, we write two methods: fname (), sname (), and an attribute age. In this example, the basic data type is returned. In fact, it can also implement more complex data types.
Using system;
Using system. runtime. interopservices;
Namespace anamespace
{
Public interface asignatures
{
String fname ();
String sname ();
Int age {Get ;}
}
[Classinterface (classinterfacetype. autodual)]
Public class Aclass: asignatures
{
Public String fname ()
{
Return "very ";
}
Public String sname ()
{
Return "happy ";
}
Public int age
{
Get {return 24 ;}
}
}
}
Compile ActiveX Controls
For those that do not know how to compile outside Visual Studio IDE, you must find the C # compiler csc.exe in the following folders:
\ Windows \ Microsoft. NET \ framework \ v2.0.xxxxx
Put your aclass.csfile in the csc.exe folder. Go to the command line and execute the following command:
CSC/T: Library Aclass. CS
Client registration component
You can register components in multiple ways. For example, creating an installation file or self-extracting a file can be quickly downloaded from a browser. In our example, we simply register in the client command line mode. Run the following command in the same folder:
Regasm Aclass. dll/TLB/codebase
Make sure that the. NET Framework has been installed on the client.
Use ActiveX Controls
Create an ActiveX control using JavaScript and call methods and properties. The returned values are displayed in the dialog box. BelowCodeThis section describes how to access the properties and methods of ActiveX controls.
<HTML>
<Head>
<Script language = "JavaScript">
<! -- Read ActiveX Object -->
VaR OBJ = new activexobject ("anamespace. Aclass ");
<! -- Access method -->
Alert (obj. fname ());
Alert (obj. sname ());
<! -- Access attribute -->
Alert (obj. Age );
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
Run (*Note: You need to enable "initialize and execute scripts for ActiveX that are not marked as secure scripts" in the local security settings."), For Firefox or Safari browser, the API plug-in is required.