在code绑定一个按钮单击事件的背后 [英] Binding a Button click event in code behind

查看:113
本文介绍了在code绑定一个按钮单击事件的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在隐藏文件我的code建立一个按钮,希望点击功能绑定到不同的按钮,现有的点击功能。我该如何处理呢?我希望像一些简单的:

 按钮B =新按钮();
b.onClick = otherClickEvent();

但显然,这不是可行的。我失去了一些东西在这里。我知道的OnClientClick,但这只是事物的一面JS明显。

交易
解决方案

 按钮B =新按钮();
b.Click + =新的EventHandler(b_Click);

和后来在页面上

 私人无效b_Click(对象发件人,EventArgs的发送)
{
    您code
}

I'm building a button in my code behind file and want to bind the click function to an existing click function of a different button. How do I handle this? I was hoping for something simple like:

Button b = new Button();
b.onClick = otherClickEvent();

but apparently that's not doable. Am I missing something here. I'm aware of OnClientClick, but that only deals with the JS side of things apparently.

解决方案

Button b = new Button();
b.Click += new EventHandler(b_Click);

and later on the page

private void b_Click(object sender, EventArgs e)
{
    your code
}

这篇关于在code绑定一个按钮单击事件的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆