Thursday, February 9, 2012

Ispostback in

In short, you use it every time you need to execute something ONLY on first load.
The classic usage of Page.IsPostBack is data binding / control initialization.
if (!Page.IsPostBack)
   //Control Initialization
   //Data binding

Things that are persisted on View State and Control State don't need to be recreated on every post back so you check for this condition in order to avoid executing unnecessary code.
Another classic usage is getting and processing Query string parameters. You don't need to do that on post back.

Postback actually works fairly simply by submitting the form to itself (for the most part). The javascript code is actually put on your page:
<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;




More detail about

No comments:

Post a Comment