I have ASPX web page which has a Button on it. Once user click this button, request is submitted to server and button click event handler is executed.
I have some logic that must reside on Page.Load, but this logic depends if request has been submitted by button click. Based on page life cycle event handlers executes after Page Load.
Question: How in Page load I can find out what event handlers are going to be executed after Page Load?
@akton's answer is probably what you SHOULD do, but in case you want to go off the reservation and determine what is causing a postback early on in the lifecycle, you can interrogate the postback data to determine what was clicked. This will NOT give you what actual functions/handlers will be executed during event handling, however.
First, if something other than a
Button
/ImageButton
caused the postback, the ID of the control will be in__EVENTTARGET
. If aButton
caused the postback, there is something "cute" ASP.NET does: it ignores all other buttons so that only the clicked button shows up on the form. AnImageButton
is a little different, because it will send coordinates. A utility function you can include:All that being said, if you can refactor your control/page to delay execution, your code will be much cleaner/more robust if you use the paradigm suggested by @akton.
There may be a better solution to the problem. Do you want the code to only run when the page is first loaded and you are using postbacks? If so check the Page.IsPostBack property. If the code does not need to run before other event handlers, move it to OnPreRender because it fires after event handlers.
These helped me a lot: I wanted to save values from my gridview, and it was reloading my gridview /overriding my new values, as i have IsPostBack inside my PageLoad.
SOURCE: http://bytes.com/topic/asp-net/answers/312809-please-help-how-identify-button-clicked