ASP. NET Server-side control principle analysis, asp.net server-side control

Source: Internet
Author: User

ASP. NET Server-side control principle analysis, asp.net server-side control
There are two types of server-side control trigger events:

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

<Input type = "submit" name = "Button1" value = "Button" id = "Button1"/>

The type is type = "submit". After a widget is clicked, it will be submitted in form. After it is clicked, it will be sent to the server as a parameter. The parameter is the control's name attribute = the value of the control, the server will know that the button is clicked based on the value of the received control's name attribute, so that the click event of this button is triggered on the server side.

When we add the name attribute to the Button tag of the server-side control, the server will remove it during front-end rendering, this also proves that the name of the clicked button is obtained through the name value in the background.

2. Background event triggering for other server-side controls

The server will automatically trigger a script for the event of the server control:

 1 <script type="text/javascript"> 2 //<![CDATA[ 3 var theForm = document.forms['form1']; 4 if (!theForm) { 5     theForm = document.form1; 6 } 7 function __doPostBack(eventTarget, eventArgument) { 8     if (!theForm.onsubmit || (theForm.onsubmit() != false)) { 9         theForm.__EVENTTARGET.value = eventTarget;10         theForm.__EVENTARGUMENT.value = eventArgument;11         theForm.submit();12     }13 }14 //]]>15 </script>

Then add the js code to each control event:
<A id = "LinkButton1" href = "javascript :__ doPostBack (& #39; LinkButton1 & #39;, & #39; & #39 ;) "> Click </a>

To call doPostBack to send the corresponding trigger information to the background. There are two parameters: the first is the name of the trigger event control, and the second is the event parameter.

3. The server will automatically generate a hidden domain VIEWSTATE, save the value of the server control, and save the status when the page is sent back.

<Input type = "hidden" name = "_ VIEWSTATE" id = "_ VIEWSTATE" value = "Examples + watermarks + CveDXrKw6PmUBnHUp85WYCvEi9n8IHtvZ8 ="/>

 

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.