Is there a function or property to indicate if a button has been clicked?

EE168
EE168 used Ask the Experts™
on
I know that when you click a button, the "Page_Load" event occurs before the "Button_Clicked" event.

For example I have a button named "Button1". I click "Button1" and have an event for it when it is clicked. When the button is clicked I know that the "Page_Load" event will occur first. In that code I would like to see if "Button1" is the reason for the "Page_Load" event firing.

I want to know if there is a function or property that will tell if the Button has been clicked.

Protected Sub Page_Load ()
If (Button1.? = )  (Is there a function or property that will let me know if Button1 has been clicked?
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Kind of, there are 2 approaches you can take:
1. There is a form variable called __EventTarget which contains the client ID of the control that caused a postback. This only works for controls which initiate a postback through Javascript (eg. linkbuttons and the like) but you can force controls such as buttons to do this by setting UseSubmitBehaviour = false on the button.
Then checking Request.Form("__EventTarget") to see which control caused the postback.
2. If you don't want to set UseSubmitBehaviour=false on the buttons then you can check the form variable directly that corresponds to the button you want to check. eg. Request.Form(Button1.ClientID), if this has a value then Button1 was clicked. This won't work on javascript controls.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial