0

I bind the click event handler server-side, and pass some additional parameters. This binding is done as part of a repeater data bound event. When I click the LinkButton the event handler's never fired. Can't work out why:

lnkUp.Click += (lnkSender, eventArgs) => { lnk_Click(lnkSender, eventArgs, int1, int2, string1); };

(I've checked lnkUp is not null etc.).

The event handler:

 void lnk_Click(object sender, EventArgs e, Int32 int1, Int32 int2, String string1)
 {
      //Do something fantastic
 }

In case you're wondering about the mark-up:

<asp:LinkButton ID="lnkUp" runat="server" Text="SomeText"/>

1 Answers1

3

You try associate click event handler in ItemCreated event, not in ItemDataBound. (Best practise)

And adjust your bind just in ! isPostBack section , in order to don't erase your registered event.

void Repeater_ItemCreated(Object Sender, RepeaterItemEventArgs e) 
{
   .....
}

       

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • Thanks a lot! Appreciate your answer. Do I still have access to the data item here? I need it. –  Sep 12 '12 at 12:30
  • I'am happy to help you DeeMac, in lyfecycle phase itemCreated is before ItemDataBound, you access data in ItemDataBound – Aghilas Yakoub Sep 12 '12 at 12:32
  • string1 comes from a part of the data item, which is used as an argument in the method call - so I'm not sure how I'll use ItemCreated in this case, thanks again. –  Sep 12 '12 at 12:33
  • 1
    Ok i understand your technical choice, DeeMac thank you, you are nice good luck my friend – Aghilas Yakoub Sep 12 '12 at 12:45