ASP. NET getting started tutorial (2)

Source: Internet
Author: User
What is Asp.net web forms

The Asp.net web forms page framework is an upgradeable Universal Language Runtime (CLR)ProgramModel, used to dynamically generate Web pages on the server side. (It is awkward for Americans to speak. In fact, web forms is a page written by Asp.net)
As a rational evolution of ASP (ASP. NET provides syntax compatibility with existing ASP), the ASP. NET web forms framework is designed to address the shortcomings of the ASP mode. It provides:
· Create and use reusable user interface controls, encapsulate common functions, and reduce page developers' writingCode.
· Provide developers with page logic with clear structures and good styles (rather than the "spaghetti" structure ).
· Provides powerful WYSIWYG page development tools (ASP code is not transparent to tools)
This section provides high-level code and provides a preliminary introduction to the key functions of ASP. NET web forms. The subsequent sections will further analyze ASP. NET web forms Functions

Write the first web forms page

ASP. NET web forms pages are text files with the aspx extension. They can be configured through the IIS virtual root directory tree. When the browser client requests a. aspx resource, ASP. NET Runtime library analyzes and compiles the target file to form a. NET Framework class. This class can be used to dynamically process the upcoming requests. (Note: The. aspx file is compiled only when it is accessed for the first time. The compiled result is reused in future requests ).
You can simply change the HTML file extension to aspx to get an Asp.net file (No code needs to be modified ). For example, the following example shows an HTML page that collects user name and category preferences and submits a form when you press the button.
C # intro1.aspx

[run] | [source program]
Note: When you click the lookup button, nothing will happen. This is because the. aspx file only contains static html (no dynamic content ). Therefore, the same HTML will be returned to the client at every round-trip, and the form field content will be lost during the submission process.
use ASP's <%> reference flag
Asp. Net to provide syntax compatibility for existing ASP pages. This compatibility includes <%> code reference blocks, which can be used together with HTML content in the. aspx file. These code blocks are executed from the top down when being referenced.
the following example shows how to use the <%> reference flag in HTML blocks for loop (increasing the font size in turn)
C # intro2.aspx
[run] | [source program]
Note: Unlike ASP, the code used in the above <%> block is actually compiled, rather than the interpretation and execution of the script engine. Therefore, the running efficiency is improved.
ASP. NET page developers can use the <%> code block to dynamically modify HTML output, just like ASP. For example, the following example shows how to use <%> to return the results submitted by the client.
C # intro3.aspx
[run] | [source program]
Note: <%> the code block provides a powerful method to implement ASP.. NET page customization and operation text output, but does not provide a clear structure of the program mode. As in the preceding example, if a developer only uses the <%> code block, the developer must manage the Page Status and the value sent after the explanation in the request sending round-trip.

Introduction to ASP. NET Server controls
In addition to programs that use (or replace) <%> to compile dynamic content, Asp.net page developers can use ASP. NET Server controls to design web page programs. When declaring server space in the. aspx file, use the specific Asp.net tag or the HTML Tag containing the runat = "server" attribute. When HTML tags are used as controls, they are defined in the namespace system. Web. UI. htmlcontrols. Any labels that cannot be mapped to the control are assigned the system. Web. UI. htmlcontrols. htmlgenericcontrol type.
The following example uses four server controls: <form runat = Server>, <asp: textbox runat = Server>, <asp: dropdownlist runat = Server>, and <asp: button runat = Server>. At runtime, these server controls automatically generate HTML content.
C # intro4.aspx
[Run] | [source program]
Important: I do not know how to accurately translate this term in the round trip (rount trips) passed to the server. It means to submit data from the client to the server, in the process of returning data from the server, these server controls automatically keep the value entered by any client (it replaces the round-trip loop, how to save form fields in <input type = "hidden"> ). In addition, you do not need to support any client scripts to maintain data in ASP. NET.
In addition to standard HTML input controls, ASP. NET allows developers to use richer custom controls on pages. For example, the following example shows how to use the <asp: adrotator> control on the page to implement dynamic wheel display advertisement.
C # intro5.aspx
[Run] | [source program]
Important: a detailed list of all built-in server controls is provided in the web forms controls reference section of this tutorial.

========== To be continued...

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.