Another blog post on this: http://www.cnblogs.com/Silicon-Fado/archive/2009/04/21/1440437.html
__viewstate: page state information is stored in the client (information stored in VIEWSTATE, enableviewstate= "true" control state information).
__eventtarget: Page callback triggering event page callback trigger event:
__doPostBack (' Button2 ', ') indicates that the call button Button2 the corresponding Click event control on the back end of the callback trigger event:
__doPostBack (' Test1$button1 ', ') represents the click method that invokes the Button1 button in the TEST1 control
__eventargument: The parameters of the page callback trigger event such as: __doPostBack (' Button1 ', ' AA ') can be used request.form["__eventargument" in the backend to obtain
. NET auto-generated some client-side code to pass data back and forth with some script functions of their own
=====================================================================
Today's work encountered a need according to the GridView specific content to determine whether the popup window, and the GridView contains pagination, sorting, etc., they can not be directly from the query string, or form simple analysis. This is due to the existence of the __doPostBack method and its close association with __ Eventtarget and __ eventargument.
The Eventtarget parameter of
function __doPostBack (Eventtarget, eventargument) is the name of the GridView control, and the eventargument parameter is the command word. When deleted, the eventargument parameter is the start of the delete, and when inserted, the eventargument parameter is the beginning of the insert, and if it is an edit, the eventargument parameter is the start of the edit; The eventargument parameter is the select Start.
============================================================
The __doPostBack method is called after the client triggers the event. The Eventtarget and event arguments that represent the triggered control source eventargument are paid to two hidden fields __eventtarget and __eventargument, and then the form is submitted, on the server side according to __eventtarget and __ Eventargument to determine which of the controls was triggered by what event.
< script language= "javascript" > function __doPostBack(eventTarget, eventArgument) { var theform = document.WebForm2; theform.__EVENTTARGET.value = eventTarget; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } < /script> |
The postback mechanism of =================================================================asp.net we know that ASP. NET output to the client will be converted to HTML, page render to After the client, the client's HTML code will contain the following code:
<input type= "hidden" name= "__eventtarget" id= "__eventtarget" value= ""/>
<input type= "hidden" name= "__eventargument" id= "__eventargument" value= ""/>
<input type= "hidden" name= "__viewstate" id= "__viewstate" value= "/wepdwukmta0ndq2ote5owrk281l4eak7izt10hzg+ Beoyouwbq= "/>
<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>
Where the hidden field _eventtarget represents the control that triggered the event. _eventargument represents an additional parameter for the event. In order for the page to be able to read the original state data of the server control after postback, the ViewState technology is used in ASP. ViewState technology essentially uses a default name of __ ViewState hidden type form fields to hold and pass data (the data is BASE64 encoded string values after serialization). Control events become Javascript:__dopostback (' Button1 ', ') after the event of the render
For example, the following looks
<input type= "button" Name= "Button1" value= "Button1" onclick= "Javascript:__dopostback (' Button1 ', ')" id= "Button1" />
===============================================================================================
This place can be seen making a blog post: http://www.cnblogs.com/Silicon-Fado/archive/2009/04/21/1440437.html
Only two web Server control triggers the postback of the page itself, and all other controls trigger the page's postback through the __doPostBack function, which generates a __dopostback when the page is parsed ( Eventtarget, eventargument) method. Eventtarget is the callback parameter (additional data associated with the control) that is the id,eventargument of the control that caused the loopback. These two parameters are saved by the hidden two form fields __ Eventtarget and __ eventargument, respectively. Use these two hidden forms to find the control ID and the loopback parameter that caused the page loopback.
This is traversed when you trigger the __doPostBack event. Request.Form.AllKeys, you see these two hidden forms.
Because the content that is ultimately presented to the browser is HTML content, there is no exception to the use of ASP. To implement the postback mechanism of WebControl. Only in the original submit to make a fuss.
I see that the ASP. NET now adds two hidden input to the page, and these two input are used to hold the ID and parameter of the control that triggered the postback. That's what most of us recognize:
The first parameter of __doPostBack (OBJ1,OBJ2) is the control ID, and the second parameter is the parameter of postback. Then you can use request.form["__eventtarget" and request.form["in the background" __ Eventargument "] Gets the control ID and parameters.
It is very simple to realize the seemingly magical, thought that the interior has what advanced processing process! So lightweight implementation of the postback mechanism, admire admiration! As long as we understand the above code, the use of __dopostback should not be difficult. Can say __ Dopostback is such a simple thing.-_-| |
However, it is also important to note that the WebControls, Button and Imgbutton are heterogeneous, they do not use __dopostback to achieve postback. Why So, Maybe because the button in HTML is the function that triggers the Submit event. ASP. NET is just to make some of the original HTML can not trigger the submit of something, only to get out __ Dopostback to achieve. For the original can submit the button, and why superfluous it.
You can find the button in the background. Why is that? Don't know, hehe. During the submission of the button, The button takes the ID of the button itself as a key to the Request.Form, and its value is the value of the button's Text property, which is passed back to the server. So you can loop the Form.keys in the background to execute the corresponding function by taking the button that was submitted. Imgbutton is the same, the difference is that It does not use the ID of ImageButton as Request.Form key, it is with the ImageButton ID Plus. x and. Y as key, in the Request.Form add two key-value pairs, the two key values should be corresponding to the image size of ImageButton , after understanding this rule, we can still have a certain way to get whether it is caused by ImageButton postback.
As below I write an example of a simple page,
(1) The drop-down list in the page is rendered in hyml.
<select name= "DropDownList2" onchange= "Javascript:settimeout (& #39; __doPostBack (\& #39;D ropdownlist2\ & #39;,\& #39;\& #39;) & #39;, 0) "id=" DropDownList2 ">
<option value= "--Please select--" >--Please select--</option>
<option value= "Household Furniture 1" > Household furniture 1</option>
<option selected= "selected" value= "Home furniture 2" > Home furniture 2</option>
<option value= "Household Furniture 3" > Household furniture 3</option>
<option value= "Household Furniture 4" > Household furniture 4</option>
</select>
Can see
Onchange= "Javascript:settimeout (& #39; __doPostBack (\& #39;D ropdownlist2\& #39;,\& #39;\& #39;) & #39, 0) "id=" DropDownList2 ">
The drop-down list here uses the __doPostBack function to trigger the postback of the page, and the page resolves to generate a __dopostback (Eventtarget, eventargument) method for the class.
(2) For the button, that's it.
<input type= "Submit" Name= "Button1" value= "Confirm" id= "Button1"/>
The button is not used for __dopostback, because in ASP. WebControls, Button and Imgbutton are heterogeneous, and they are not implemented postback using __doPostBack. Why So, Maybe because the button in HTML is the function that triggers the Submit event. ASP. NET is just to make some of the original HTML can not trigger the submit of something, only to get out __ Dopostback to achieve. For the original can submit the button, and why superfluous it.
===================================================================================================
When the button is clicked, the __doPostBack event is triggered, the _dopostback event submits the form to the server, and the server side __eventtarget this hidden The value of field finds the corresponding server-side control. Next, the server looks at whether control implements the call to page raisepostbackevent, which is defined as follows:
protected virtual void RaisePostBackEvent (IPostBackEventHandler sourcecontrol, String eventargument)
{
Sourcecontrol.raisepostbackevent (eventargument);
}
function to invoke the control within the
protected virtual void RaisePostBackEvent (String eventargument)
Base. Validateevent (this. UniqueID, eventargument);
IIF (this. CausesValidation)
{
This. Page.validate (this. ValidationGroup);
}
This. OnClick (Eventargs.empty);
This. OnCommand (New CommandEventArgs (This.commandname, this.commandargument));
}
__doPostBack method parsing __viewstate __eventtarget __dopostback __eventargument