Use Windows Form Controls in IE Browser (1)
Author :: Thiru Thangarathinam
Translation: Qiu Feng
introduction
In the past, web programmers often use ActiveX controls in their web programs to implement some fat clients. But now developers can easily create objects through Microsoft.NET Framework, and it is convenient to cut into use in the IE browser. Developers can realize a wealth web client by creating a Windows Form Control in the IE browser. In this article, we will know how to create a Windows Form Control and use it in IE. In the process of using the Form Control in your browser, we will demonstrate how to provide a rich web client display through a form control, and the form control is used to call remote Web Service to get data. At the same time, we will also know how to use the .NET security model to provide a safe operating environment for our form controls.
If you have experience in developing a web program with Java, you will be familiar with Java Applets. It is a small program running in the browser. Java Applets will run when the browser opens an HTML document containing an Applet tag. The WINDOWS form works in the WEB page. It is very similar to Java Applets. In this implementation, you create a form control and plus a rich Windows Form Control Style, followed by it. When the browser loads the web page, the code contained in the Windows control will be executed. This will be useful in a local area network or extended network program. For example, I want to develop a base with a web that has a fat client characteristic.
An important feature of .NET is to closely combine IE. For example, we can use Windows Form Controls in IE without notifying users to need additional things. This doesn't need to register anything .NET CLR will provide code security access capabilities.
When you create a Windows Form Control, you will have the features provided by the Form Class. For example, you can use the Windows Form Control Authentication technology to verify the accuracy of the input data. Similarly, you can even call Web Service in your form control. By using these technologies, you can create a rich, robust, dynamic application of the base with the .NET platform.
Remarks: According to the original text, replace the logging into Chinese, run the environment: operating system Windows 2003, .NET Framework 1.1. Here: Talking here: Open the browser in the debugging process to enter the full address. If the form control will not be displayed in a file mode; additional debugging of the process can be a single source file. However, I run the component generated under the debug version, not release, interested readers can try.
carried out
In this section, we will understand how to create a Windows Form Control and use it in IE. Five steps are listed below to complete this process.
1. Create a Windows Form Control
2. Create an HTML document with an Object tag that identifies the Windows control
3. Configure the virtual path of the control
4. Set code access
5. Runput control
Let's take a look at the various steps above.
1. Create a Windows Form Control
In this step, we create a simple Windows Form Control. The function implemented by the control is to display "Hello World" to the user. Let's first create a Windows control library project named HelloWorldControl, modify the default user control for HelloWorldctl. Then add a Label to the control, named LBLDisplayMessage, and add a button BTNClick. When the user clicks the button, the following code will be executed to display the message to the user.
Private void btnclick_click (Object sender, system.eventargs e) {
this.lbldisplayMessage.Text = "Hello World";
}
Then it is to compile him to generate an assembly.
2. Create an HTML page
In this step, we will create an HTML document and insert the Object tab inside. The entire document looks as follows:
Hello World Control
In this label's classID property, we specify the path of the component created in the first step and the complete limit of the component. The entire full name includes namespaces and the entire class name. We can clearly see the component name and qualified name # segmentation in the code. These two partial parameters are combined together to identify the uniqueness of the control. Of course, you can write a client script by name the unique ID to HelloWorldControl1.
3. Configure virtual paths
Have
HTML
Page, now create a
HelloWorldControlhost
Virtual directory, actual directory
D: / my programs / hellpworldhost
This catalog contains
HelloWorldControl.dll
with
HellpWorld.htm
file. When setting the virtual directory, you need to pay attention to setting the execution permission is "pure script". If set to "script and executable script" permissions. That control may not work properly (
I am set into "scripts and executable scripts" under IIS6.
). You can open the properties of the virtual directory to confirm the settings, the settings window is as follows: 4. Set code access
If this web is accessed in the local area network, he will work properly. If the web is accessed via the Internet, you need to set up Internet Explorer to modify security properties to allow him to run. You can join the home page to a trusted site. If you need to set the Tools menu of IE -> Internet Options -> Security -> Trusted site, click the site button to add your website to it. Next, when you open your browser, you will see it correctly.
5. Runput control
To run this control, we look at the HTML page that contains the control in the browser. If you click on this button on the page, then the control will display "Hellp World". The execution page is as follows: In this example, we implemented how to create a Windows Form Control and then display in the IE browser. In the next section, we have implemented access Web Service through the Form Control on the client browser.