views:

276

answers:

3

I have an update panel and a list of buttons that trigger it. I need some way to find out which button was pressed when the load method (which is caused by the triggers) goes off, but I can't figure it out. Sender doesn't cast into the trigger, but the update panel itself.

I need to perform some action based on which button was pressed.

Any advice?

I'm using ASP.NET / C#

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" OnLoad="LocationList_Load">

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnLocMiddleEast" />
    <asp:AsyncPostBackTrigger ControlID="btnLocUSA" />
    <asp:AsyncPostBackTrigger ControlID="btnLocNewZealand" />
    <asp:AsyncPostBackTrigger ControlID="btnLocAustralia" />
    <asp:AsyncPostBackTrigger ControlID="btnLocEurope" />
    <asp:AsyncPostBackTrigger ControlID="btnLocRepublicOfIreland" />
    <asp:AsyncPostBackTrigger ControlID="btnLocNorthernIreland" />
    <asp:AsyncPostBackTrigger ControlID="btnLocWales" />
    <asp:AsyncPostBackTrigger ControlID="btnLocScotland" />
A: 

If you're debugging, you can check the stack trace.

Neil Barnwell
don't you think he wants to know the source of the trigger at runtime (not debug)
Martin
He didn't say, and I didn't want to assume. Feel free to provide an alternative answer if you feel I've missed anything.
Neil Barnwell
+1  A: 

Normally I would just create an individual Click event handler for each button, and then write the specific code that should be triggered in each event handler.

Pete
Doesn't this cause the page/buttons to postback though? I don't really want to refresh the page in order to run the codebehind
SLC
No. That doesn't trigger a complete postback, because the update panel has registered that events send by those buttons should generate an async postback
Pete
Note. When using an update panel, everything that happens server side is the same as with a normal form postback. The difference is how the request is made (asynchrounous) and what data is returned (only the HTML that goes into the UpdatePanel(s) + viewstate).
Pete
A: 

Check the answer I gave to this question:

Making a difference between AsyncPostbacks in nested update panels

Basically you should check the ScriptManager.AsyncPostBackSourceElementID for the trigger.

Zhaph - Ben Duguid