Wednesday, March 28, 2012

Why must I click button twice?

Hi,
I create the click event code for the button on the page, but all buttons ( include the paging button on the DataGrid) I must click twice , then the event fired. What should I do to fire the event immediately if the button are clicked.Are you adding your DataGrid to your web page at runtime?
one common mistake is to set up everything in page load.

page load comes before all control events, so if your doing everything in page load, you may miss values getting changed by something like a button click which comes AFTER Page Load and BEFORE PreRender.

i moved all my code out of PageLoad and into PreRender whenever it could be dependant on something that could change via a button click etc...
Thanks, mbanavige
I moved the databind() to page_prerender event, it works fine now.
B.T.W, would you give some more information on prerender event, because i also have some other problems, such as the button click event does not fire, search button I also must click twice before the page get the correct search string
Thank you very much.
PreRender occurrs just before all the server controls are turned into HTML to be sent to the client in the Render event.

I use PageLoad to do some page setup. My pageload event is very very light.
Almost all my work is done in PreRender because it occurrs AFTER all the control events have fired. clicks, ddl's etc...

Pretty much anything that depends on a user interaction/postback should be performed in PreRender and NOT PageLoad. Then you wont miss any state changes that occur in the control events.

0 comments:

Post a Comment