Setting LinkButton's OnClick event to method in codebehind

前端 未结 2 1266
夕颜
夕颜 2021-02-07 12:56

I\'m constructing a LinkButton from my codebehind, and I need to assign the onclick to a method, and pass a parameter with it too. I have this so far:

LinkButton         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 13:22

    The function prototype for this event is:

    protected void lnkdel_OnClick(object _sender, EventArgs _args)
    {
        LinkButton src = (LinkButton)_sender;
        // do something here...
    }
    

    Assign it with:

    LinkButton lnkdel = new LinkButton();
    lnkdel.Text = "Delete";
    lnkdel.OnClick += new EventHandler(lnkdel_OnClick);
    

提交回复
热议问题