I'm writing some code which mimics the effect of making a postback to a page by executing exactly the same web request that would be generated on clicking a button that triggers the page postback.
The problem is that the response from the web request is not the same as what I get when clicking on the button.
On investigating, I see that even though the Page_Load event is triggered and handled when I execute the web request, the handler for the button click is not being executed (meaning that either the event is not triggered, or it's being triggered but not handled - I'm guessing it's more likely the former case).
So my question is - how does ASP.NET know what button has been clicked so that it can invoke the appropriate handler?
I thought that this was done by using the __EVENTTARGET param - I have correctly set this in the post body of the web request, but this made no difference.
I looked at the decoded __VIEWSTATE argument, but I couldn't see anything obvious in there.
Can anyone provide any further help?
EDIT: Just to be clear, I am not asking how to add a click handler to a web application.
Rather, I am looking at an application that already has a button click event handler, and I want to know how asp.net figures out from an incoming web request what button click event handler code to invoke.