Home > ASP.NET 2.0 > Difference between Page.IsPostBack and Not page.IsPostBack.

Difference between Page.IsPostBack and Not page.IsPostBack.

Monday, 28 April, 2008 Leave a comment Go to comments

Page.IsPostBack is for forms that are runat=”server”. It is mostly used for same page validation, same page operations, … anything really same page!

It is also used to help keep bandwidth and rendering times down.

The main reason why people use IsPostBack is to stop taping the databases everytime a request is made. If you are on your default page and just do work via that page, you can use the if Not page.ispostback then statements to populate information. When pages are posted back to the sever and then rendered back to the client, they don’t have the need to repopulate the information since it was just populated. It is all kept in the viewstate and read back without using precious resources on the server.

It’s a very good and handy tool to know, and very easy to know as well! Any information that is not variable dependant should be only posted when the user first shows the page.

For another example, let’s say you are using menus that pull information from the database, articles that are previewed on a side bar for users with a link to the full article, and a search function that posts results that can be ordered by date, name, etc. Now, with the IsPostBack functionality, you can add the statement to all information that does not change when a request is made on the same page. You can add the “If Not Page.IsPostBack Then” for the menus and articles since the information does not change in anyway when a user clicked to have the search results ordered by name! This means that you do not have to tap the database three times, but only once! The information about the menus and articles are held in the viewstate so you don’t have to repopulate them.

Then for the “If Page.IsPostBack Then” statement, you can use for registration purposes for your site, post comments, etc. all by the Page.IsPostBack function. No code in the “If Page.IsPostBack Then” statement is fired when the page is requested by the client for the first time; And vice-versa, the “If Not Page.IsPostBack Then” function is only fired when the page is called for the first time, then uses viewstate to fill in the areas it is required to for every postback after that.

Hope this helps..


Page.IsPostBack Is used to check if the user posted back to the page. Meaning they clicked a button or changed a field in the form that causes it to post back to itself.

Putting Not usually is used to check the initial load of the page.

You only need to fill databound fields on the initial load, so you put all your databinding code in the Not page.IsPostBack. The values are saved in the viewstate and can only be read by the form if it gets posted back to itself.

So, if it is a postback dont do databinding if its not a postback do databinding.

Categories: ASP.NET 2.0 Tags:
  1. Monday, 28 April, 2008 at 4:39 pm
  2. Tuesday, 21 October, 2008 at 8:14 am

    Thats explain much! TQ

  3. Dipak
    Thursday, 30 April, 2009 at 11:14 am

    This is good solution

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: