Author: Su Hong is super REVIEW code to bind ASP.NET provides an important new technology. This article will show you how to use code binding techniques to implement the Separation of the web page representing layer and business logic code, and recommends that you use code binding technology to realize the reuse of code. In another article, we will give additional implementation techniques for implementing code reuse. Code Binding Technology in ASP.NET When you build your own ASP.NET application, the main advantage of using code binding technology is: it allows you to be easy to see (those HTML code) And server-side controls) with your performance code (these codes may be VB, C # or any other .NET supported language) free separation open. This advantage is more obvious when you have a multiplayer development team to develop the same project. A person may be responsible for the design and writing of the web page, while another person may be the development of the specific program responsible for the page. Thus, by dividing the respective operating range, the two sides can be easily achieved without destroying the work of the other party. Of course, to do the normal operation of the page, the good low-class color dive dive, when we use the code binding technology, the visualty code is existing in the file being an ASPX. . This is a new .NET extension, used to describe an ASP file. It is difficult to do any script in the previous ASP to have only HTML code (of course if you are meaningless). However, the code binding technology allows the ASPX file only contains HTML code and server-side controls, and allows developers to completely use object-oriented ways to implement a solution. This mechanism to access this ASPX file in a separate code file can achieve the above ideas. These files are compiled into a separate binary when the browser first issues a request, as shown below: The code binding file is a separate file that can be written using any .NET support. For example, use Visual Basic .NET to write these files, its extension will be "VB". This code binding code contains all events related to layers, functional functions, methods, and more. Each ASPX file can only be implemented by a code binding file. Of course, through a certain job, code binding technology can be used in a variety of environments that need to be reused code. Every Aspx file has their own code binding files, and multiple features similar ASPX files can share a public code binding file. This article shows how to achieve the most basic code binding technology of your ASPX file, and discuss how code binding techniques are applied to code reusable. In the subsequent article, we will introduce. Other technologies provided by the .NET architecture can also easily implement code reuse, such as user controls, compiled collections, and more. Let's take a look at an example to see how to implement code binding technology. For simplicity, our example will start with a simple search page. When we step by step through the code binding technology, we will be able to see how the code binding technology implements a code reuse ASPX file. In order to make the ASP.NET program running normally, you must install the .NET architecture beta1. If you want to make the program proposed in this article, you must install SQL Server2000. Step by step to implement code binding technology First, we need to build one. ASPX file. In this ASPX file, we need to use the @PAGE instruction to explain that we are binding a code. In order to do this, we need to set two properties: SRC and inherits. The src property specifies a file containing the actual code. If this property is not available, the class specified in the property inherits is looking for the parameters passed from the compile time. The inherits property specifies the class that exists in the source file. This class needs to be derived from the Page class.
Our specific examples are as follows: <% @ page language = "VB" autoeventwireup = "false" src = "search.vb" inherits = "Search"%> Next, we need to add an appropriate control to establish our user interface. Since our example page is a simple search page, we only need to join a small part of the control. In addition to some tag tags, we need to add a search text box, a button submitted, and a DataGrid control to display content in the database.
The following is the code: <% @ page language = "vb" src = "search.vb" inherits = "search"%>
head>