__doPostBack Function
Introduction
It is quite amazing to note that only two of the ASP.NET web server controls cause a postback. All the other controls use the JavaScript __doPostBack function to trigger the postback. In this article you will learn about the __doPostBack function and how it works.
_doPostBack Function
The best way to understand the working of the __doPostBack function is to dissect the function into small pieces and explore each piece one at a time. Let us take a look at the function.
Listing 1 - _The __doPostBack function
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
Analysis
The __doPostBack function takes two arguments, eventTarget and eventArgument. The eventTarget contains the ID of the control that causes the postback and the eventArgument contains any additional data associated with the control. Note that the two hidden fields, “__EVENTTARGET” and “__EVENTARGUMENT,” are automatically declared. The value of the eventTarget and eventArgument are stored in the hidden fields. The two hidden variables can be accessed from the code behind using the forms/params collection.
Read full artical here.
One more good artical on How postback works in ASP.NET.
It is quite amazing to note that only two of the ASP.NET web server controls cause a postback. All the other controls use the JavaScript __doPostBack function to trigger the postback. In this article you will learn about the __doPostBack function and how it works.
_doPostBack Function
The best way to understand the working of the __doPostBack function is to dissect the function into small pieces and explore each piece one at a time. Let us take a look at the function.
Listing 1 - _The __doPostBack function
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
Analysis
The __doPostBack function takes two arguments, eventTarget and eventArgument. The eventTarget contains the ID of the control that causes the postback and the eventArgument contains any additional data associated with the control. Note that the two hidden fields, “__EVENTTARGET” and “__EVENTARGUMENT,” are automatically declared. The value of the eventTarget and eventArgument are stored in the hidden fields. The two hidden variables can be accessed from the code behind using the forms/params collection.
Read full artical here.
One more good artical on How postback works in ASP.NET.
Comments
Post a Comment