c# - Post back issue -


OK Let me ask questions like this: Generally, there is no page cycle:

page_load < / P>

Submit On-Click and / or Handler

Page_load.

If so, the values ​​of control on page should be during onclick / submit handler? Value by users, or value from page_load?

page load event before control events So if you are in the page load event If the values ​​change, these changes will overwrite any values ​​the user chooses, and in the control incidents, you will see the values ​​set in the page load.

If you start something in the page load event but only when it first comes to the page, you can use IsPostBack:

  if (! IsPostBack ) {// Getting Started Which You Just Want  

Here is a good one with many more details.

Here is a simple example sequence: <

  • The fire of the page load
  • The page is render and sent to the browser
  • On the user Some works on the page (clicks on a button, a text box changes, which is set to AutoCostback, etc.)
  • A post on the browser page
  • Page loads The fire (again) this time IsPostBack is true. Also keep in mind, this is not the same "page" object because it was in # 2 because every HTTP request The new page object Ri way. For example, member variables will not be saved on all requests.
  • The appropriate control events fire (clicks, text changes, etc.)
  • The page is render and is sent back to the browser

  • Comments