The more I use ASP.NET, the more if (!IsPostBack) {}
seems pointless...
First example:
For example, I just Googled an issue, they said use this
When there is no need to repeat the operation other than the first time.
use it with expensive operations (such as getting data from a database or populating ListItems) that 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,
First you need to understand what is postback,when you start your project in Visual Studio,
if you have a if statement
which checks whether isPostBack
is true
or false
in your Page_Load
method, at this point, isPostBack
is false
, means it is not a postback
, then what is postback,
now click a button
(if you don't have a button,please add one and the button click method as well), at this point, you send a request back to the server, the server then response, this process is the so called postback
, which is triggered by clicking the button
,
one thing you really need to notice, the Page_Load
method will be executed again, not only the Button_click
method will be executed, so now, the isPostBack
is true
, means it is postback, yes, it really is a postback, because you clicked the button.