Knowing which control caused postback

P

PokerMan

Hi

I have a few controls on apage that cause a postback. But want to handle a
postback differently depending on which one of these controls fired the
postback. How do we do this? c#.

Thanks
 
M

Mark Rae

I have a few controls on apage that cause a postback. But want to handle a
postback differently depending on which one of these controls fired the
postback. How do we do this? c#.

Each control which generates the postback will fire its own postback event
i.e. the one for which it is wired up...

E.g. if you have two <asp:Button> controls each with its own OnClick()
event, they will each fire their own OnClick() event on postback... Put
different code in each event as required...

Is that what you mean...?
 
E

Eliyahu Goldin

The easiest way is to handle server-side events for the controls in separate
event handlers. If you need to know the postback source in the Page_Load
event, that fires before control events, you can check
Request.Form["__EVENTTARGET"] . It will work only if the postback was
initiated be a control other that a button.
 
G

George Ter-Saakov

Usually all generated events have a parameter "ender"
like click of the button event
protected void btnDelete_OnClick(object sender, EventArgs e)

sender will point to the object that causes that event.



George.
 
W

wajimam

Hi

I have a few controls on apage that cause a postback. But want to handle a
postback differently depending on which one of these controls fired the
postback. How do we do this? c#.

Thanks
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top