Knowing which control caused postback

  • Thread starter Thread starter PokerMan
  • Start date Start date
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
 
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...?
 
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.
 
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.
 
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
 
Back
Top