If you have used Java to develop Web applications, you will be familiar with Java applets, a small program that basically runs in a browser. When the browser loads HTML code containing the Java applets flag, Java applets executes the code. The Windows Forms control on the webpage runs in a similar way as Java applets. We can use a variety of classes provided by the Windows Forms technology to develop Windows Forms controls, and then deploy these controls in the web page. When the browser loads these web pages, the Code contained in the Windows Forms control is executed.
One of the greatness of. NET is its ability to seamlessly integrate with IE. For example, we can even activate a Windows Forms control from IE without the user's knowledge. Although all the functions of Code Access Security provided by. net clr are used, this is done without registration.
When developing a Windows Forms control, we inherit all the functions provided by the Windows Forms class. For example, we can use the Windows Forms Control Verification Technology to perform extensive verification of user input data. Similarly, we can call remote Web services from the form control. By using all these technologies, we can use the. NET platform to develop rich and powerful applications.
Implementation
In this section, we will learn how to create a simple Windows Forms control and host it in IE. The following are five steps to activate the Windows Forms control in IE:
· Create a Windows Forms control.
· Create an HTML document containing the object flag that identifies the Windows Forms control.
· Configure the virtual directory required for correctly activating the control.
· Configure code access permissions.
· Run the control.
Next we will learn in detail every step above.
Create a Windows Forms Control
In this step, we will create a simple Windows Forms control that displays "Hello World" information to users. As shown in the political summary, we will first create a New Visual C # Windows Control Library project named HelloWorldControl.
Once a project is created, the default user control is changed to HelloWorldCtl. We will add a label control named lblMessage and a button named btnClick to the user control. When you click the button, the program will execute the following code to display a simple information to the user:
Private void btnClick_Click (object sender, System. EventArgs e) { LblDisplayMessage. Text = "Hello World "; } |
Now that you have created a control, let's compile the project and create executable code.
Create an HTML webpage
In this step, we will create an HTML document and insert the object flag used to activate the Windows Forms control. The HTML webpage is as follows:
<Html> <Body> <P> Hello World Control <br> </body> <Object id = "HelloWorldControl1" classid = "http: HelloWorldControl. dll # HelloWorldControl. HelloWorldCtl" Height = "500" width = "500" VIEWASTEXT> </Object> <Br> </Html> |
In the classid attribute of the object flag, we specify the path as the full name of the control library combination and control. The full name of the control includes the namespace and control class name. From the code above, we can see that the combination body and the full name of the control are separated by the # sign. These two parameters constitute a unique control identifier that identifies the control. Because it is uniquely identified by the HelloWorldControl1 name, we can also write client script code for this control.
Configure virtual directory
). In addition to configuring virtual directories, setting the execution permission of virtual directories to Scripts is also very important. If you set the execution permission to Scripts & Executables, the control will not be correctly activated. By opening the Properties window of the virtual directory, we can verify the permissions of the virtual directory.
Configure Code Access Permissions
If the control is publicly executed on the enterprise intranet, but if you want to run the control from an Internet website, you need to configure or modify the Security Policy for IE to run it. This can be done by viewing hosted web pages as part of trusted segments. To set your site as part of a trusted zone, in IE, you can choose tools> Options> Security> trusted sites and add your sites to the list, click "OK. In this way, the control will be correctly executed the next time you browse the Web page, because the Internet license has been set.
Run controls
To run a control, you only need to browse the HTML webpage hosting the control in the browser. On the displayed HTML page, if you Click the "Click Here" command button, the control displays the "Hello World" message as shown in.
In this example, we primarily demonstrated how to create a simple Windows Forms control and host it in IE.