Asp. NET hands-on Tutorials (3)

Source: Internet
Author: User
Tags implement interface net object model query versions client

Handling Server Control Events

Each ASP.net server control has the characteristics of an object model, including properties, methods, and events. ASP.net developers can use this object model to dynamically modify the page and interact with the page.

The following example shows how the asp.net page developer manipulates the Text property of the <asp:label runat=server> control by handling the onclick event of the <asp:button runat=server> control.

This simple example is functionally equivalent to the "Intro3" example described earlier. However, you can see how simple and clear this version of Server-based controls is!

Using custom server-side controls

Asp. NET provides 45 built-in server controls for use (for more information, see Web Forms Control Reference). In addition to using the built-in ASP.net controls, developers can also use controls provided by third parties.

The following example shows a simple calendar control (Calenda). This control is declared using the <acme:calendar runat=server> tag on the page. Notice that the <% register%> at the top of the page uses TagPrefix to register "ACME", using the namespace description to execute the control's namespace. The ASP.net page parser will use this namespace at run time to load instances of the calendar-managed class.

In this example, the Calendar control is designed to perform "advanced run" in more than 5.5 versions of Internet Explorer and perform "low-level runs" on other browsers. This monitoring of the browser version is possible in the built-in server controls provided by ASP.net. He generates DHTML output for the IE5.5 version. DHTML output does not require a cycle of server and client cycles. For other versions of the browser, this control generates a standard HTML3.2 document. In the interaction, the client and server-side cycles are required.

Important: When writing code, the page designer does not need to consider whether the browser is "advanced run" or "low-level run" when it accesses the page. The Calendar control itself encapsulates the ability to handle different browser requests.

Lists, data, and data binding

Asp. NET has a built-in set of data tables and lists of controls that can provide customized user interface drivers to implement requests for databases or other data sources. For example, the following example shows how the <asp:datagrid runat=server> control uses the SQL database query language to implement data binding to the book information collection.

The <asp:datagrid runat=server> DataGrid control uses a traditional table interface to provide a simple and quick way to display data results. In addition, ASP. NET developers can also use <asp:datalist runat=server> DataList controls and custom ItemTemplate templates to customize how data is displayed.

Note that the <asp:datalist runat=server> control allows the end user to accurately control the structure and appearance of each item in the list (using ItemTemplate template properties). The control automatically handles wrapping of content between two columns at the same time (the user can control the number of columns through its RepeatColumns property)

The following example provides a <asp:datalist runat=server> control to alternate alternating rows.

Note that the controls, data models, and page users here are the same as the previous example. The difference is that the example declares other templates in the code.

Form validation Controls
The ASP.net Web Forms page framework provides a set of server validation controls that are easy to use and powerful to check for errors in client form input and, if necessary, to display prompts to the user.
Adding a server validation control to a page is like using a different server control. Different validation controls are different, such as input range checking or pattern matching, and so on. You can use the RequiredFieldValidator validation control to ensure that users do not skip a field that should enter data.
The following example demonstrates how to use the <asp:requiredfieldvalidator runat=server> control in a page to validate the contents of a TextBox and DropDownList control.
C # intro11.aspx
[Run] | [Source code]

Note The validation controls also provide advanced run and low-level run support. The High version browser mode executes on both the server side and the client (using Java scripts and DHTML), and the low panel browser mode only performs validation on the server side. The program pattern is the same in both cases.

Note that the ASP. NET page developers can check the Page.IsValid property at run time to determine whether all validation controls on the page pass. This provides a simple way to deal with business logic. For example, the following example performs a page.isvalid check first when performing a database query on a particular taxonomy.

Web Forms Code Separation

Asp. NET supports two ways to create dynamic pages. The first is as demonstrated in the previous example, and the page code is declared in the same. aspx file. Another way to----familiar code separation is to make the page code cleaner, separating the code from the HTML content and becoming a complete, separate file.

The following example demonstrates the use of code-splitting technology to write asp.net pages

Summary of this chapter

1. ASP. NET provides a simple yet powerful way to build a dynamic Web user interface

2. The asp.net Web Forms page can be automatically adapted to any browser client (no script library or cookie support is required)

3. The ASP.net Web Forms page provides syntax compatibility with existing ASP pages

4. asp.net server controls provide an easy way to encapsulate common functions.

5. asp.net provides 45 built-in server controls. Developers can also use controls provided by third parties.

6. asp.net server controls can automatically design advanced dynamic mode and low-level browser HTML mode

7. The asp.net template makes it easy to customize the appearance of the list server control, thereby customizing the appearance of the page data display.

8. ASP.net validation controls allow for easy validation of client or server-side data



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.