In asp2 the Page.IsPostBack() property comes in rather handy at times but the key to its use is having a clear understanding of the property and when exactly it returns true or false.
To help me determine this, I checked the MSDN library and found the following Summary for the property: "Gets a value indicating whether the page is being loaded in response to a client postback (in which case it returns TRUE), or if it is being loaded and accessed for the first time (in which case it returns FALSE)."
Sad to say, this summary is actually a tad misleading. When it comments "or if it is being loaded and accessed for the first time", this to me gives the impression that ONLY the FIRST TIME that page is loaded/accessed (by that user), the property will return FALSE. This however, is not the case.
The actual times when the Page.IsPostBack() property returns FALSE are: a) when the page is being accessed (by that user) for the first time AND also b) if the page even though accessed already is being accessed again from another page (ie you went to Page 1 already but currently have browsed to Page 2... Now, whilst on Page 2 you click a link that takes you back to Page 1. Here, the Page.IsPostBack() property in Page 1 will return FALSE).
Hopefully this should clear things up a bit, it sure did for me.
tagged: professional // Comments [0]
Related posts:Select a random row in MS SQL...Regular expressionsVS2005, ASP.NET 2 & DLLs, DLLs..MS's ASP.NET and.. PHP2-way databinding cascading drop down lists within a FormViewApplicationName Property when customising providers
Disclaimer The posts on this blog are provided "AS IS" with no warranties. The opinions expressed herein are my own personal opinions and do not represent any other person's views in anyway.