Use client scripts

Source: Internet
Author: User

Abstract: Although ASP. NET performs most of its operations on the server, some operations may be better processed on the client. Scott Mitchell explains how to add client code to ASP. NET pages and controls.
Content on this page
Introduction
Create a base class as the basis for adding client scripts
Add client scripts from the code hiding class
Execute client code based on the response to user operations
Implement common client functions
Summary
Related books
Introduction
When using dynamic and Web-based scripting technology, similar to traditional ASP or PHP, developers must have a keen understanding of the logic, temporary and physical separation between the client and the server. For example, for user operations that trigger server-side code execution, developers using traditional ASP must explicitly enable the user's browser to return requests to the Web server. Creating such an interaction can easily take a lot of development time and cause unreadable code.
Microsoft ASP. NET, by using Web forms, helps ease the burden of binding user events to code execution on a specific server, blurring the line between the client and the server. Use ASP. NET and minimal work, developers can quickly create the following webpage, which has a large number of Interactive User Interface Element buttons, drop-down lists, and so on, and these are based on the operations of end users, you can choose to run the server code. For example, ASP. add a drop-down list. If the selected drop-down list item changes, you only need to add the DropDownList Web Control and set its AutoPostBack attribute to True, create a SelectedIndexChanged event handler for the drop-down list. If you use the traditional ASP to complete the preceding tasks, you need to write a lot of complicated HTML, client JavaScript, and server-side script code. to provide you with the necessary script code and server-side event model.
Although Web forms in ASP. NET greatly simplify running server scripts when performing client operations, misuse of such functions may lead to unacceptable performance. Although the Web form hides the complexity involved, each time you need to execute the server code, the end user's browser must resubmit the form to return the request to the Web server. When submitting a form, all form fields (text box, drop-down list, and check box) must return their values at the same time. In addition, the view status of the page is also returned to the Web server. All in all, each time a webpage is sent back, thousands of bytes of data will need to be potentially sent back to the Web server. Therefore, frequent sending back may soon make Web applications unavailable, especially for users who still use dial-up connections. By pushing the function to the client, you can reduce the need for frequent sending back.
Note: ASP. NET Web forms generate a hidden form field titled VIEWSTATE, which contains a 64-bit encoded representation of the Web Control's changed status in Web forms. Based on the Web Control, the view status ranges from dozens of bytes to tens of thousands of bytes. For more information about View status, see my article Understanding ASP. NET View State.

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.