How does IsPostback technically work?
The page looks for the existence of a __PREVIOUSPAGE
form value.
From Reflector:
public bool IsPostBack
{
get
{ //_requestValueCollection = Form or Querystring name/value pairs
if (this._requestValueCollection == null)
{
return false;
}
//_isCrossPagePostBack = _requestValueCollection["__PREVIOUSPAGE"] != null
if (this._isCrossPagePostBack)
{
return true;
}
//_pageFlags[8] = this._requestValueCollection["__PREVIOUSPAGE"] == null
if (this._pageFlags[8])
{
return false;
}
return ( ((this.Context.ServerExecuteDepth <= 0)
|| ( (this.Context.Handler != null)
&& !(base.GetType() != this.Context.Handler.GetType())))
&& !this._fPageLayoutChanged);
}
}
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;
theForm.submit();
}
}
Marks answer shows you the server side code that is run.
Is Postback is implemented as such (using Reflector):
public bool get_IsPostBack()
{
if (this._requestValueCollection == null)
{
return false;
}
if (this._isCrossPagePostBack)
{
return true;
}
if (this._pageFlags[8])
{
return false;
}
return (((this.Context.ServerExecuteDepth <= 0) || ((this.Context.Handler != null) && !(base.GetType() != this.Context.Handler.GetType()))) && !this._fPageLayoutChanged);
}
So unless you take into account all these parameters, it will not be possible to trace it.