如何从字符串中调用click事件

本文关键字:调用 click 事件 字符串 | 更新日期: 2023-09-27 18:26:55

这是我的问题。

    string btn = "btn7";
    //this is the problem.
    btnClone.click += this.controles[btn]_click ;

所以我喜欢使用一个字符串将事件共享给另一个按钮,该字符串是必须的。

我希望有人能帮助我。

如何从字符串中调用click事件

通过id查找控件的更标准的方法是

Button b = (Button)FindControl(btn);

如果你不知道id ,你也可以这样搜索

   Button oldButt = this.Controls.OfType<Button>().(b => b.Name == btn).First();