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 ="/>