ASP. NET event (callback) Mechanism

Source: Internet
Author: User

Abstract:
In ASP. ent, there are two mechanisms for implementing page PostBack. No matter which callback method is used, Form submission is final.

I. Original Form submission

The buttons and imagebutton controls in webcontrols are converted

HtmlCode

 
<Input type = "Submit" name = ""/> <input type = "image" name = ""/>
Ii. Form submission using JavaScript and hidden forms

In addition to buttons and imagebutton, other webcontrols controls implement the page return mechanism in this way. The procedure is as follows:
1. If there are server controls except button and imagebutton on the page, the ASP. NET page framework automatically adds two hidden forms to the page.

HTML code

<Input type = "hidden" name = "_ eventtarget" id = "_ eventtarget" value = ""/> <input type = "hidden" name = "_ eventargument "id =" _ eventargument "value =" "/>

2. The server automatically generates the following JavaScript method to process event sending.

JavaScript code

<SCRIPT type = "text/JavaScript"> <! -- Var theform = Document. Forms ['form1 ']; If (! Theform) {theform = Document. form1;} function _ dopostback (eventtarget, eventargument) {If (! Theform. onsubmit | (theform. onsubmit ()! = False) {theform. _ eventtarget. value = eventtarget; theform. _ eventargument. value = eventargument; theform. submit () ;}/// --> </SCRIPT>

3. Each control that will trigger a server event will call the above Code in the response client event.
The following uses the <asp: linkbutton> server control as an example to describe the ing between the server and the client:

HTML code

<A id = "linkbutton1" href = "javascript :__ dopostback ('linkbutton1','') "> linkbutton </a>
 
 
 
Note: server controls such as <asp: checkbox> and <asp: textbox> do not automatically generate the _ dopostback method called by JS on the client.


4. after the client triggers an event, it calls the _ dopostback method. The eventtarget and eventargument parameters of the triggered control source are respectively paid to the two hidden domains _ eventtarget and _ eventargument, and then submits the form, on the server side, determine which control event is triggered Based on _ eventtarget and _ eventargument.

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.