[Original] the world's first ASP. net2.0 control library without viewstate

Source: Internet
Author: User

First, let's see:

Viewstate plays an important role in ASP. NET:

Viewstate is ASP. A very important feature of net is used to maintain the server status of the Control During page sending back, so that we can easily write in the button-clicking event handler function.Code:

Label1.text = textbox1.text;

For details about viewstate, refer to a classic article. I believe many people have read this article. It is summarized as follows:

1. When the page is loaded for the first time, the server control saves its attributes to a hidden field _ viewstate on the page.

2. When the page is PostBack, the value of _ viewstate when the form is submitted is also submitted to the background. ASP. NET will restore these attributes from this hidden field.

In traditional website development, viewstate works exactly the same way and greatly simplifiesProgramWorkload. However, with the rise of Ajax, especially in the client interface applications rendered by pure JavaScript,

The implementation of viewstate is a little too slow.

Pages created using extaspnet:

In pages created using extaspnet, all the page content is rendered by a client in Javascript. Let's take a typical page as an example:

If you open the pageSource code, You will find that in addition to several lines of HTML code between <body> and </body>, most of the JavaScript code generated on the server side:

But don't worry. Programmers don't need to write this code (these are automatically generated by extaspnet). What programmers need to pay attention to is the aspx tag and C # code:

Disadvantages of viewstate in rich client applications:

In the above example, if you continue to use the viewstate mode of ASP. NET, let's look at what will happen:

1. First page loadingBecause the content of the rich text box on the page is set through the C # code, this attribute will appear in the _ viewstate field:

At the same time, because the entire page is rendered by JavaScript, this attribute will also be passed to the Javascript script on the page, as shown in:

It can be seen that data duplication occurs when the page is loaded for the first time.

2. Click "Get HTML editor content "., The content of the rich text box above will be set to the textarea below, at this time and C # source code is as follows:

Let's take a look at the Ajax response data. Because the data changes in textarea need to be reflected in the previous section, we also need to update the JavaScript and viewstate data:

This once again results in a waste of data transmission. In a page that uses a large number of server controls, this waste is sometimes amazing.

What should I do if I discard viewstate and extaspnet?

Does giving up viewstate in a new client framework that advocates simple programming mean giving up the convenience of using C # To operate server controls in PostBack? Obviously, this is impossible!

The only way is to implement the viewstate mechanism suitable for Ajax data transmission. extaspnet is one step ahead in this respect and creates a brand new xstate concept, in this way, the convenience of C # operations on server controls in PostBack is not abandoned, and any data transmission waste is rejected.

The following example shows how to implement xstate in the latest extaspnet v2.3.1:

1. First page loadingThe data in the rich text box only has one copy of the generated Javascript. Because viewstate is not used, _ viewstate only saves the property of controlState:

2. Click "Get HTML editor content ".In this case, the Ajax response data is not duplicated either:

Comparison between viewstate data and viewstate data:

In the above example, we start from the data transmission volume of the first load and PostBack page respectively:

Response Data (using viewstate) response data (not using viewstate)

First load 5068 4922

Click the first button 1251 709

Note:

Extaspnet is a set of professional Asp.net control libraries with native Ajax support and rich UI effects,
The target is to create a web application without viewstate, JavaScript, CSS, updatepanel, and WebServices.

Example: http://extasp.net/
Source: http://extaspnet.codeplex.com/

If you like extaspnet, you can chat with everyone through the following QQ:

Extaspnet technology exchange group: 1: 158028499 (saturated), 100 people, Founder: sanshi
Extaspnet technology exchange group 2: 111870015 (saturated), 200 people, Founder: aitao Course
Extaspnet Technology Exchange Group 3: 102333298 (saturated), 200 people, Founder: aitao Course
Extaspnet Technology Exchange Group 4: 123899180 (saturated), 200 people, Founder: aitao
Extaspnet technology exchange group:, 52447 (unsaturated), 500 people, Founder: Song ☆abor◆ Luo
Note:
1. All groups are for technical communication and refuse any form of advertisement. Once discovered, they are immediately kicked out of the group.
2. If you want to contribute to the extaspnet group, please create a group number and send it to my Gmail mailbox (only accept the advanced group and super group, thank you ).


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.