1

This is my Mark up Page where I have a Button to search data from DB and display in the Grid

And this is my code behind

if (!IsPostBack)
    {
        LblInfo.Text = "Page Loaded";
    }

    if (IsCallback)
    {
        LblInfo.Text = "Page Called Back";
    }

please explain why every time IsCallback = fasle?

Indrajit
  • 51
  • 3
  • 9
  • 1
    Hard to say more considering information you've provided. [MSDN](http://msdn.microsoft.com/en-us/library/system.web.ui.page.iscallback.aspx): `true if the page request is the result of a callback; otherwise, false.` – sll Feb 21 '12 at 15:12
  • 1
    Callbacks aren't the same as postbacks... – Grant H. Feb 21 '12 at 15:12

1 Answers1

4

IsCallBack is a special kind of postback.

The only time IsCallBack is going to be true is if IsPostBack is also true.

Therefore their is no way to get to your "Page Called Back" code. See What is the difference between Page.IsPostBack and Page.IsCallBack?

The two variables can result in exactly 3 conditions:

  • IsPostBack and IsCallBack are both false: initial page load.
  • IsPostBack is true; IsCallBack is false: full postback occurred.
  • IsPostBack is true; IsCallBack is true: request came from ajax.

There is no situation in which IsPostBack will be false and IsCallBack will be true.

So your code should be:

if (!IsPostBack) {
    { 
        LblInfo.Text = "Initial Page Loaded"; 
    } 
} else {
    if (IsCallback) 
    { 
        LblInfo.Text = "Page Called Back"; 
    } else {
        LblInfo.Text = "Page Posted Back";
    }
}
Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245