Asp. NET hands-on Tutorials (2)

Source: Internet
Author: User

What is ASP.net's web Forms

The ASP.net Web Forms page framework is an upgradeable universal language runtime (CLR) program model that is used to dynamically generate WEB pages on the server side. (Americans talk is awkward, in fact, Web Forms is asp.net written page)

As a logical evolution of ASP (asp.net provides syntax compatibility for existing ASP), the ASP.net Web forms framework is designed to address the deficiencies of the ASP model. It provides:

· Create and use reusable user interface controls, encapsulate common features, and reduce the amount of work that page developers write code.

· Provides developers with clear, orderly, and style-structured page logic (rather than "spaghetti" structure).

· Provides powerful WYSIWYG (WYSIWYG) page development tools (ASP code is opaque to tools)

This part of the textbook provides a high level of code to make a preliminary introduction to the key features of ASP.net WEB forms. Subsequent chapters will delve deeper into the functionality of ASP.net WEB forms

Write the first Web Forms page

The ASP.net Web Forms page is a text file with an aspx extension. They can be configured through the IIS virtual root tree. When the browser client requests an. aspx resource, the ASP.net runtime database analyzes and compiles the target file to form a. NET Framework class. This class can be used to dynamically process a request that is about to begin. (Note:. aspx files are compiled only the first time they are accessed, and the compiled results are reused in future requests).

You can simply change the extension of the HTML file to aspx to get a asp.net file (no code needs to be modified). For example, the following example shows an HTML page that collects the user's name and classification preferences, and then submits the form when the button is pressed.

C # intro1.aspx

Important: Note that nothing happens when you click the lookup button. This is because the. aspx file contains only static HTML (no dynamic content). Therefore, the same HTML will be returned to the client at every round-trip, and the form's field contents are lost during the commit process.

Use ASP's <%%> reference flags

Asp. NET provides syntax compatibility for existing ASP pages. This compatibility includes <%%> code reference blocks, which can be mixed with HTML content in an. aspx file. These blocks of code are executed from the top when they are referenced.

The following example shows how to use the <%%> reference flag in an HTML block to implement a loop (increase the font size in turn)

C # intro2.aspx

Important: Unlike the ASP, the code used in the <%%> block above is actually compiled, rather than interpreted by the scripting engine. Therefore, the execution efficiency of the runtime is improved.

Asp. NET page developers can use <%%> code blocks to dynamically modify the output of HTML, just as with ASP. For example, the following example demonstrates how to use the <%%> implementation to respond to client-submitted results.

C # intro3.aspx

Important: The <%%> code block provides a powerful way to customize and manipulate text output from ASP.net pages, but does not provide a structured program pattern. As the above example, developers only use <%%> code block, they must be in the request to send a round-trip, manage the page state, their own management interpretation of the value sent out.

Asp. NET Server Control Introduction

In addition to using (or rather as a substitute) <%%> to edit dynamic content, asp.net page developers can use ASP.net server controls to design Web page programs.

When declaring server space in an. aspx file, use a asp.net-specific label or an HTML tag that contains the runat= "server" attribute. HTML tags are used as controls and are defined in the namespace System.Web.UI.HtmlControls. Any label that cannot be mapped to the control, is assigned the System.Web.UI.HtmlControls.HtmlGenericControl type.

The following example uses 4 server controls: <form runat=server>, <asp:textbox runat=server>, <asp:dropdownlist Runat=server>, and <asp:button runat=server>. At run time, these server controls automatically generate HTML content.

C # intro4.aspx

Important: In a round trip to the server side (Rount Trips-----I don't know how to translate the word accurately, he means to submit data from the client to the server and then return the data from the server process), These server controls automatically maintain the value entered by any client (it replaces the cycle round trip, where the form fields are stored in the <input type= "hidden" method). Also, please note that ASP. NET to maintain the data does not need any client script support in addition to supporting standard HTML input controls, ASP. NET allows developers to use richer custom controls on a page. For example, the following example shows how to use the <asp:adrotator> control on a page to implement dynamic wheel display advertising C # intro5.aspx



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.