_ Dopostback is an important part in Asp.net. It is necessary to have a deep understanding of the ins and outs of _ dopostback. In fact, __dopostback is a very simple JS function.CodeAs follows:
_ Dopostback
< Input type = " Hidden " Name = " _ Eventtarget " ID = " _ Eventtarget " Value = "" / >
< Input type = " Hidden " Name = " _ Eventargument " ID = " _ Eventargument " Value = "" / >
Function _ Dopostback (eventtarget, eventargument ){
If ( ! Theform. onsubmit | (Theform. onsubmit () ! = False )){
Theform. _ eventtarget. Value = Eventtarget;
Theform. _ eventargument. Value = Eventargument;
Theform. Submit ();
}
}
Because the content finally presented to the browser is HTML content, the use of Asp.net technology is no exception. To implement the webcontrol PostBack mechanism, you can only do it on the original submit.Article. Ms presents us with this kind of exquisite thinking!
I can see that Asp.net now adds two hidden inputs to the page, which are used to store the IDs and parameters of the control that triggers PostBack. This is what most of us realize:
The first parameter of _ dopostback (obj1, obj2) is the Control ID, and the second parameter is the PostBack parameter. then you can use the request in the background. form ["_ eventtarget"] and request. form ["_ eventargument"] obtains the Control ID and parameters.
It's easy to implement what seems amazing, and think there is a profound internal processing process! This lightweight implementation of the Asp.net PostBack mechanism is admirable! As long as we understand the above Code, the use of _ dopostback should not be difficult. It can be said that _ dopostback is such a simple thing.-_-|
However, in Asp.net's webcontrols, buttons and imgbutton are different. They do not use _ dopostback to implement PostBack. in this case, it may be because the button already has the function to trigger the submit event in HTML. .asp.net is just to make the original HTML something that cannot trigger the submit, _ dopostback is implemented. for the button that can be used to submit, why bother to do so. (For personal understanding only, not verified !)
Therefore, if it is the PostBack of the button, the request cannot be used in the background. form ["_ eventtarget"] and request. form ["_ eventargument"] for obtaining the Control ID and parameters. so how can we get it? Check the Code:
Get button
Foreach (string StrInRequest. Form)
{
Control C=Page. findcontrol (STR );
If(C is button)
{
Control=C;
Break;
}
}
The button can be found in the background using the above method. Why? I don't know. during the button submission process, the button uses the ID of the button as the request. A key of form. Its value is the text attribute value of the button and is returned to the server. therefore, you can cycle form in the background. keys obtains the submitted button to execute the corresponding function. imgbutton is similar. The difference is that it does not use the ID of imagebutton as the request. form key, which is added with the ID of imagebutton. X and. Y as the key, in the request. form adds two key-value pairs, which correspond to the image size of imagebutton. After understanding this rule, we can still determine whether the PostBack is caused by imagebutton in a certain way.
Understanding the PostBack mechanism is helpful for us to understand the event triggering process of Asp.net. We should make good use of _ dopostback to make the client and server more flexible to interact with each other for a better customer experience.