Explain the “AutoPostBack” feature in ASP.NET?
“AutoPostBack”
is the mechanism, by which the page will be posted back to the server
automatically based on some events in the web controls contained within a page.
In some of
the web controls, the property called “AutoPostBack”, which if
set to “True”, will send the request to the server when an event
happens in the control. The default the value is always set to
“False”.
Whenever
the “AutoPostBack” attribute to “True” for any of the
web controls, the .NET framework will automatically insert the following few lines of
code to the HTML generated to implement this functionality:
- A JavaScript method with name __doPostBack (eventtarget, eventargument)
This method is inserted to the HTML source to implement the “AutoPostBack” functionality, it will submit the form when ever called. The two parameters in this method i.e. eventtarget and eventargument do the actual work of selecting the control to fire the event. This method will set the value of the __EVENTTARGET hidden variable with the eventtarget parameter and __ EVENTARGUMENT value with the eventargument parameter.
- Two Hidden
variables with name __EVENTTARGET and __EVENTARGUMENT
The __EVENTTARGET hidden variable will tell the server, which control actually does the server side event firing so that the framework can fire the server side event for that control.The __ EVENTARGUMENT variable is used to provide additional event information if needed by the application, which can be accessed in the server. - OnChange JavaScript event to the control
This event is added by the framework to any of the controls where the “AutoPostBack” is set to “True”, this method will fire the client side OnChange event and call the __doPostBack event with the name of the control where the OnChange event is fired.
Comments
Post a Comment