Asp. NET Server-side control principle analysis

Source: Internet
Author: User

There are two types of server-side control triggering events:

1. The server-side control Button is rendered as the client's

<input type= "Submit" Name= "Button1" value= "button" id= "Button1"/>

Type type= "Submit" Such controls will be submitted via the form form after clicking, and will be sent as parameters to the server after clicking, the parameter is the control's Name property = control's value, The server side will know that this button is clicked, based on the value of the Name property of the received control, to trigger the Click event on the service side.

When we add the name attribute to the server-side control button tag, the server removes it from the front-end rendering, which also proves that the background is using the name value to get the clicked button names.

2. Background event triggering for other server-side controls

The server automatically causes the event touch of the server-side control to occur as a script:

1<script type= "Text/javascript" >2 //<! [Cdata[3 varTheform = document.forms[' Form1 '];4 if(!theform) {5Theform =Document.form1;6 }7 function__doPostBack (Eventtarget, eventargument) {8     if(!theform.onsubmit | | (Theform.onsubmit ()! =false)) {9Theform.__eventtarget.value =Eventtarget;TenTheform.__eventargument.value =eventargument; One theform.submit (); A     } - } - //]]> the</script>

Then add the JS code to each control's corresponding event:
<a id= "LinkButton1" href= "Javascript:__dopostback (& #39; linkbutton1& #39;,& #39;& #39;) ">Click</a>

To invoke Dopostback to send the corresponding trigger information to the background, there are two parameters, the first is the name of the control that triggered the event, and the second is the event argument.

3. The server automatically generates hidden domain VIEWSTATE, saves the value of the server control, and saves the state when the page is postback

<input type= "hidden" name= "__viewstate" id= "__viewstate" value= "dfh5nmwjx1dnsxzn46y8jnrw6phzm5uvakten6wj9+ 0qh5o2vtlskki844uxjfmnj5w9xjbw+cvedxrkw6pmubnhup85wycvei9n8ihtvz8= "/>

Asp. NET Server-side control principle analysis

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.