Overview of ASP. NET auto-sending

Source: Internet
Author: User

To use automatic sending back, set the autopostback attribute of webcontrol to true (default value: false ). After setting, ASP. NET uses JavaScriptCodeAnd the server code.

The details are as follows: If you create a page that contains one or more Web controls, these controls use autopostback, Asp. net adds a _ dopostback () JavaScript function to the HTML page. When called, it triggers sending back and sends all form information back to the web server.

ASP. NET also adds two hidden texts. The _ dopostback () function uses them to submit information to the server. The information includes the ID of the control that triggers the event and other related information. The two hidden texts are at the beginning, just like this:

 1   <  Div  Class  = "Aspnethidden"  > 
2 < Input Type = "Hidden" Name = "_ Eventtarget" ID = "_ Eventtarget" Value = "" />
3 < Input Type = "Hidden" Name = "_ Eventargument" ID = "_ Eventargument" Value = "" />
4 </ Div >

The _ dopostback () function is responsible for setting event-related information to their values, and then submitting the form. The _ dopostback function is as follows:

1 Function_ Dopostback (eventtarget, eventargument ){
2If(! Theform. onsubmit | (theform. onsubmit ()! =False)){
3Theform. _ eventtarget. value = eventtarget;
4Theform. _ eventargument. value = eventargument;
5Theform. Submit ();
6}
7}

The _ dopostback () function is automatically generated by ASP. NET. The length of this Code increases as the number of autopostback controls used on the page increases, because event data must be set for each control.

Finally, any control that sets the autopostback attribute to true will use the onclick or onchange attribute to associate with _ dopostback. These attributes indicate how the browser responds to the onclick and onchange events of the client JavaScript.

Below is an HTML code for dropdownlist. Its autopostback attribute is true. Each time you change the options in the list, the onchange event on the client is triggered. Then the browser calls the _ dopostback () function to send the page back to the server:

 
1<SelectName= "Dropdownlist1"Onchange= "Javascript: setTimeout (& #39 ;__ dopostback (\&# 39; dropdownlist1 \&# 39 ;,\& #39 ;\& #39 ;) & #39;, 0 )"ID= "Dropdownlist1">

In other words, ASP. NET automatically transforms the client's JavaScript events into server-side ASP. NET events and uses _ dopostback () as the intermediary.

Note: ASP. NET contains two types of controls: one is an HTML Server Control and the other is a web control. Only Web controls can be automatically sent back.

from Pro ASP. net 4 in C #2010

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.