IsPostBack in ASP.net

By: Dan Hurwitz and Jesse Liberty Viewed: 153363 times  Printer Friendly Format    


The page exposes the IsPostBack property. This is a read-only Boolean property that indicates if the page or control is being loaded for the first time, or if it is being loaded in response to a client postback. Many expensive operations (such as getting data from a database or populating ListItems) must be performed only the first time the page or control is loaded. If the page is posted to the server and then reloaded, there is no need to repeat the operation. By testing the value of IsPostBack, you can skip the expensive operation, as in the code snippets in Example 1 and Example 2.

Example 1. Testing for IsPostBack in VB.NET
sub Page_Load(ByVal Sender as Object, _
ByVal e as EventArgs)
if not IsPostBack then
' Do the expensive operations only the 
' first time the page is loaded.
end if
end sub
Example 2. Testing for IsPostBack in C#
void Page_Load(Object sender, EventArgs e)
{
if (! IsPostBack)
{
// Do the expensive operations only the 
// first time the page is loaded.
}
}


Most Viewed Articles (in Asp )

Latest Articles (in Asp)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. Nice ,Easy to understand
View Tutorial          By: Jomon at 2009-06-30 00:56:48

2. Very Good explanation . Thanks.
View Tutorial          By: Dipti at 2010-09-15 21:57:09

3. pretty simply explained
View Tutorial          By: nivedita at 2011-06-09 07:32:58

4. Very simple, clear visualized and meaning
View Tutorial          By: HIM at 2011-07-21 21:43:58

5. simple explanation.. Nice...
View Tutorial          By: Gopi at 2011-08-19 09:24:30

6. simple explanation,.. Nice....
View Tutorial          By: Gopi at 2011-08-19 09:28:47

7. Super
View Tutorial          By: Sathish godalatty at 2011-09-19 10:11:13

8. very simple
View Tutorial          By: vishu at 2011-10-07 06:38:49

9. Good..neatly explained
View Tutorial          By: jithu at 2011-10-17 11:15:24

10. So simple..Very easy to understand
View Tutorial          By: G.Tejasree at 2011-11-05 11:51:38

11. simply nice.. Thank you.
View Tutorial          By: Anil at 2011-11-30 06:36:23

12. Easy to understand
View Tutorial          By: suji at 2012-02-21 08:28:05

13. Seriously very nice explanation.... Thank You
View Tutorial          By: Pulkit agrawal at 2012-03-20 10:28:10

14. Easy to understand,thank u
View Tutorial          By: Soung Pann Wai at 2012-04-24 04:42:44

15. nice artical, very easy to understand.
View Tutorial          By: Kamlesh Tiwari at 2012-06-07 12:23:32

16. I thought it is big concept but the example which
View Tutorial          By: Nambu karthy.R at 2012-06-27 13:18:20

17. NICE EXPLANATION >>>THANK UUUUUU
View Tutorial          By: PraVeen at 2012-07-05 10:12:25

18. Thank You So Much . .. .. .
Very Nice Expl

View Tutorial          By: salman at 2012-07-05 13:22:11

19. good one in a very simple way...
View Tutorial          By: Harshita Sharma at 2012-07-15 13:28:46

20. got it in one glance ...
thank u

View Tutorial          By: pravallika at 2012-07-21 20:05:59

21. It helped me, also. Thank You :).
View Tutorial          By: Roska at 2012-07-22 20:19:30

22. Very Nice Explanation.
View Tutorial          By: Anuj Bansal at 2012-08-25 12:23:59

23. Great!
View Tutorial          By: justauser at 2012-08-31 13:57:58

24. Buenisimo, me ayuda a salir de un problema, cosas
View Tutorial          By: Emilio, Guatemala at 2012-09-25 15:33:11

25. u hav done Nice job..
View Tutorial          By: Rakesh at 2012-10-01 16:00:14

26. Nice explaination.. But wats the use of it? Can i
View Tutorial          By: kavita at 2013-04-04 07:10:14

27. Hi,

This is a very informative arti

View Tutorial          By: Andrew Deniel at 2013-05-29 11:42:43

28. nice ....Simple undersstanding..
View Tutorial          By: Anjaneyulu at 2013-06-15 04:43:45

29. Easy to understand.good work
View Tutorial          By: Deepika at 2013-12-13 09:33:55

30. Larryhaw
View Tutorial          By: Larryhaw at 2017-07-25 01:03:24