ASP.NET Page Events - Button Click Event Occurs After GridView Bindings

My understanding of the page event order is as follows:

Page: Download

Management: DataBind (for GridView or something else)

Management: download

Management: press (for the button)

Page: PreRender

Management: PreRender

(There are many others - but these are the ones that interest me)

It is important to note that the button click event appears after the gridview binding event. If the button causes a data change, the GridView displays the old data. I could reinstall the control in the PreRender event, but that seems absolutely ugly.

This should be a very common template (a button that updates data). How to do this together so that the GridView binds to data after clicking the Button?

+6
events data-binding page-lifecycle
source share
3 answers

The answer was in the Button Click event, after the data has been changed, call DataBind () on the page to call the GridView (and all that it needs) to check again. I did not understand that you can do this.

Thanks to Ocdecio and Mufasa - I would put your answers as useful, but so far I have no reputation.

+2
source share

ASP.NET does, by default, a lot of binding and reconnection. Reboot after the click event is normal.

+1
source share

The only reason a button event occurs after binding a GridView is because you programmed your page for this. I do not see any problems with the control binding in the PreRender event, in fact this is the only way to take action after the control event (for example, Button onclick).

0
source share

All Articles