0

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" />
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • which language and how do they trigger the update panel – mmmmmm Sep 22 '09 at 10:53
  • Since it's the click event of the button that triggers the update you already know which button cause it's click event just fired, can you put your code in the click events? – Robert Sep 22 '09 at 11:01
  • Hmm you're exactly right, it works... I thought when you clicked a button in order to run the code behind it, the page had to refresh though. Am I wrong? – NibblyPig Sep 22 '09 at 11:09
  • Nope, that's why you're using an update panel - this does a partial postback to only update the elements in the panel - note that most but not all of the page lifecycle events still fire. – Zhaph - Ben Duguid Sep 22 '09 at 11:12

3 Answers3

1

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
  • 12,206
  • 8
  • 54
  • 70
  • 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 – NibblyPig Sep 22 '09 at 11:06
  • 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 Sep 22 '09 at 11:21
  • 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 Sep 22 '09 at 11:23
1

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.

Community
  • 1
  • 1
Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
0

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

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220