Implementation of IsPostBack in page load

后端 未结 8 1039
你的背包
你的背包 2020-12-06 00:07

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

8条回答
  •  时光说笑
    2020-12-06 01:07

    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.

提交回复
热议问题