Martijn
Martijn

Reputation: 24789

Asp.net is it possible to check page_load a click event is triggered?

When a button is clicked, I would like to check whether a button is clicked in my page_load. Is this possible? I am using asp.net 2.0 C#

Upvotes: 3

Views: 4590

Answers (3)

Robin Day
Robin Day

Reputation: 102478

You can check the IsPostBack flag to see if it was a postback rather than an initial load. This may be what you're after. Also, you can check the Request.Form["__EVENTTARGET"] from which you can obtain information about the control that raised the event and therefore find out if it was one of your buttons from there.

Upvotes: 6

Henry Gao
Henry Gao

Reputation: 4936

I can think a work around by creating a hidden field and changing the value when a certain button is clicked and checking it value in Page_Load.

Upvotes: 0

kemiller2002
kemiller2002

Reputation: 115460

The button click event will fire after the page load event has. That being said, you can always check the http header to see what value is being pushed back through the request.form event. The button id will be in there if it has been fired.

Upvotes: 1

Related Questions