Difference between Page.IsPostBack and Page.IsCallBack


It is getting a value indicating whether the page request is the result of a call back. Its a special postback, so a round-trip always occurs; however, unlike the classic postback, the script callback doesn’t redraw the whole page. ViewState is not updated during a callback, it is for postback. IsPostBack is true when a method in the code behind posts a page


Checks whether the Page is accessing the server for the first time or not. Unlike the IsCallBack, the ViewState is updated. IsPostBack is true when an AJax call, calls back a the page.

How to make a callback?

In the client side JavaScript code, if GetCallbackEventReference() method is reference, then when the JavaScript code is executed, a channel to the server is opened and an HTTP request is sent to the remote ASP.NET page.[1]

references: [1] Script Callback


Working with Asp.Net variables in c#

Variables don’t automatically maintain state across page calls in ASP.NET. Asp.Net Page has a life cycle and being stateless, the information is lost at the end of this cycle, after a request has been served on the client side. One way is to use View-state for the persistence of the variables, but this significantly increases the size of a page and the data sent and received, making it slow. There are several solution for this.

  • SessionState
  • hidden fields
  • querystrings
  • Here is SessionState example

    // saving aHiddenVariable 
    // retreiving aHiddenVariable 
    string aHiddenVariable = (string)Session["aHiddenVariable"];

    Here is hidden field example.

    In HTML, we simply need to create:

    <input type="hidden" id="aHiddenVariable">

    To set it’s value in javascript:

    document.getElementById("aHiddenVariable").value = "myValue"

    In ASP.NET code-behind, you use the Request object to retrieve the value.

    string aHiddenVariable= (string)Request.Params["aHiddenVariable"];

    Here is a sample for QueryString

    // setting quesryString
    // set s=feed, "text" to search
    // retrieve variable
    string textToSearch= Request.QueryString["s"];