Check which button is clicked

S

Shawn

Hi.
I have a ToolBar with a couple of ToolBarButtons. On postback after
clicking on of the buttons Page_Load is called first then the
ToolBarButton's click event is called. Is there anyway for me to check in
Page_Load which of the buttons have been clicked?

Thanks,
Shawn
 
G

Guest

Is there any way to scan throught the ToolBar collection an object of type
Button and then by its index value identify that clicked button?
 
K

Kevin Spencer

Write an Event Handler for the ToolBarButton's click event. It isn't
necessary to use the Page_Load Sub to do all the work in your Page. In fact,
it isn't necessarily a good idea to do anything in particular in that Sub.
The Sub is for the purpose of executing processes that must run when the
Page loads. There are plenty of other events and methods for doing things in
a Page. See:

http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
S

Shawn

Kevin,
In general I don't do any particular work in page_load, but in this case I
have no choice. I'm adding checkboxes dynamically to my page and in order
to display them after a postback I have to re-create all of them. As far as
I know I have to do this in page_load. I tried doing it in
toolbar_save_ButtonClick(), but the checkboxes' state were no longer
available in ViewState. The reason why I want to know -in page_load- which
button was clicked, is because re-creation of the checkboxes is dependent on
which button is clicked, and since I can't re-create them in the buttons
click event I have to know this in page_load.

Shawn
 
K

Kevin Spencer

You can check the hidden "__EVENTTARGET" form field in the Request.Form
Collection, assuming that you have assigned a handler to the button's Click
event. This will contain the client-side ID of the Control that raised the
event.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top