GreeterLogic of ASP. NET

Source: Internet
Author: User
Tags control label

Microsoft only needs to slightly improve the Web application platform ASP. For example, it can maintain or even improve the popularity of ASP by providing a more powerful server-side scripting language or page compilation function. In fact, ASP. NET provides these two functions-but it also provides more. Simply put, ASP. NET is a revolution. In this article, I will discuss how ASP. NET improves Web programming.

In the ASP model, a page is defined in HTML and then extended through embedded scripts. In ASP. NET, the difference is that a page is a class that generates HTML. This model is called WebForm. If this name reminds you of the VB6 form control or. Net WinForms, you can touch it. For WebForms, all Web server controls are placed on one page. When this page is accessed, these controls automatically implement it in HTML format. The complex process between the browser and the server is transparent to programmers. The server automatically completes the process and allows event processing, just like WinForms.

Welcome Page
Let's start to create an example called Greeter) and see how it works. When learning a new technology, I like to split it and then combine it into a whole piece. Greeter only requires the user to enter a name and send a greeting message, but it demonstrates several main features of ASP. NET.

The Greeter page is defined in two files: Greeter. aspx, in List A, and Greeter. aspx. cs, in list B .. The aspx file defines the UI user interface of the page), and the C # file can also use Visual Basic. Net or JScript. Net) to implement the page logic in the GreeterLogic class. The @ Page command in the first line of the Greeter. aspx file binds the UI to the program logic through inheritance. In this command, the ClassName attribute specifies the name of the UI class as CreeterUI. The Inherits attribute specifies that GreeterUI is inherited from GreeterLogic.

Web server-side controls
Several Web server-side controls are stated in the <form> tag on this page. Web server controls are abstracted from standard HTML-based WebForm. They provide event processing and generate more functions than standard HTML. The Web server control is affirmed in an XML tag that references the asp namespace .. When a Web Server Control in the aspx file is executed on the page, an instance of the control is created. Each instance's reference is maintained in its corresponding base class. This allows the base class to access these controls, allow them to control these controls using programs, and handle the events generated by these controls. Specify the runat = "server" attribute for each Web server Control to indicate that the control runs on the Web server to generate appropriate HTML for the target Web browser.

The first three Web server-side controls are quite intuitive: label control label), text box, and a submit button. The last control, <asp: RequiredFieldValidator>, is different. One verification control checks the status of another control and prevents the form from being submitted when the target control is not in the correct status. In the Greeter program, the RequiredFieldValidator control is used to verify whether a data has been entered into the text box control. It does not care about the value of the data. In the initial state, the RequiredFieldValidator control is invisible. If the text box is empty when the button is clicked, no click message is generated, and the RequiredFieldValidator control displays the attribute value of ErrorMessage, B. For later browsers, The RequiredFieldValidator control generates JavaScript to verify data on the client. For earlier browsers, verification is required on the server side. In addition to the RequiredFieldValidator control, ASP. NET also provides several verification controls.

GreeterLogic class
GreeterLogic is inherited from the class System. Web. UI. Page. It declares several protected data domains to save references to the controls created in the Greeter. aspx file. GreeterLogic defines two methods. The OnInit method reloads the Page. OnInit method to add a m_Button_Click method proxy for the m_Button click event. The m_Button_Click method processes the click events generated by the m_Button Web Server Control. This click event triggers a data sending process to the server. On the server side, ASP. NET re-generates the page and restores the WEb server control status. Now the value of the text box can be obtained by accessing the TextBoxText attribute.
Configure the Greeter Program
To configure the Greeter application, follow these steps:

Create a directory for the application.

Create a bin subdirectory in the application directory.

Put Greeter. aspx in the application directory.

Run the command csc/t: library/out: Greeter. dll Greeter. aspx. cs sets Greeter. aspx. cs is compiled into a library file and then Greeter. dll is placed in the bin subdirectory of the application.

Create an IIS virtual directory pointing to the application directory.

. Aspx class generation
ASP. NET applications are processed by the iis isapi filter aspnet_isapi.dll. During the first access, the ISAPI filter generates a. NET class from Greeter. aspx in the ASP namespace and then compiles it into a binary library file. IIS will automatically search for the bin subdirectory of the application to find the GreeterLogic base class. Figure D shows the inheritance relationship of the generated class. The generated binary files are stored in a directory that stores temporary ASP. NET files generated based on the virtual directory of the application. For example, if the virtual directory of Greeter is named IntroASPNET, then Greeter. aspx may generate a binary file named effla-hh.dll and place it in files such as C: \ WINNT \ Microsoft. NET \ Framework \ v1.0.3328 \ Temporary ASP.. NET Files \ introaspnet \ b5d8b0af \ 51648ab7.

If Greeter. aspx is modified, the ISAPI filter automatically generates a binary file during the next page access.

ASP. NET implements object-oriented
So what does all this mean? ASP. NET provides a real object-oriented programming model. WebForms allows the page UI to be created and combined by inheritance independently of the page logic. There will be no more HTML and VBScript pages. The page logic is implemented using a full-featured. NET language, such as C #, Visual Basic. NET, or Jscript. NET. Furthermore, you can use all the. NET base class libraries at will to implement the page logic. The Web Server Control encapsulates the differences between different Web browsers and allows you to design Web pages at a higher level. Everything is compiled into Microsoft's intermediate language MSIL) and can be converted to machine code synchronously at runtime. There will be no performance loss in the explanatory page. If this cannot be called a revolution, I need a new dictionary.

  1. Analysis on ASP. NET Web Security
  2. Session State of ASP. NET
  3. Analysis on the attribute ASP. NET of IsPostBack
  4. ASP. NET architecture and security mechanism
  5. Overview ASP. NET Crystal Reports

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.