Implementation of IsPostBack in page load

后端 未结 8 1001
你的背包
你的背包 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:04

    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,

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题