Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button click method runs after page loads, which means page doesn't update, how can I solve this?

I have a button, which updates a value in the database. This value is used to determine what to draw on the page. Because of the page lifecycle though, the page redraws before the button click method is executed, meaning that any changes are not reflected until the page is reloaded again.

What's the best solution for this?

To clarify:

Page has a piece of text, that says "I like cats" if the database value is 1

button 'I hate cats' is pressed, which sets the database value to 0

the page reloads, but still says "I like cats"

the button click event is handled, and database value becomes 0

If the page is refreshed/reloaded, it now correctly says "I hate cats"

It should update when the button is clicked though.

like image 960
NibblyPig Avatar asked Oct 21 '10 11:10

NibblyPig


1 Answers

you can use the page prerender event. this fire after the control event in the page lifecycle.

like image 155
rauts Avatar answered Sep 24 '22 09:09

rauts