Search code examples
c#asp.netrepeaterfindcontrol

Change text of a linkbutton in a repeater


I have a repeater which displays comments related to a post.

I want to add some functionality where when the user click on the link it goes from:

report this post

to

post has been flagged

how do I access the specific lnkButton? Obviously in ItemDataBound this is easily done, but in the click method I'm not sure how I would do it.

Do I need to do something like:

I tried something like this;

LinkButton lb = repeater.FindControl(LINK_BUTTON_UNIQUE_ID) as LinkButton;
lb.Text = "blah blah blah";

but lb is always null.

Any help would be appreciated, thanks!


Solution

  • Use the source parameter of the click handler?

    protected void MyLinkButton_OnClick(object sender, EventArgs e)
    {
        LinkButton b = sender as LinkButton;
        b.Text = "Some Text";
    }