按钮的C#代码 [英] C# code for Buttons

查看:55
本文介绍了按钮的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我正在构建Web表单应用程序,并且在某种形式下我有10个Button控件。所有按钮都应显示相同的GridView,但GridView将包含不同的数据。我怎样才能找到点击哪个按钮?

Hi, i have a problem. I'm bilding Web form app and in some form i have 10 Button controls. All Buttons should show the of same GridView but that GridView will contains a different data. How can i found out which Button is clicked?

提前谢谢。

推荐答案

Webforms属于ASP.Net。因此,在ASP.Net论坛上通常会更好地提出这个问题:

http://forums.asp.net/

您必须要注意的一件事是页面生命周期:

https://msdn.microsoft.com/en-us/library/ms178472.aspx

One thing you absolutely have to be aware of is the Page Lifecycle:
https://msdn.microsoft.com/en-us/library/ms178472.aspx

有可能在多个控件上注册相同的事件(在任何GUI技术中),然后找出通过"发送者"按下的控件。参数。

您可以直接将其与特定按钮上的参考进行比较,也可以将其转换为预期类型,然后自由访问发件人。这里有两个例子:

It is possible to register the same event on multiple Controls (in any GUI technology) and then find out wich one was pressed via the "sender" argument.
You can either directly compare it to a reference on the specific buton, or you can cast it to the expected type and then access the sender freely. Here twe examples:

private void bgwPrim_DoWork(object sender, DoWorkEventArgs e) { int highestToCheck = (int)e.Argument; //Get a reference to the BackgroundWorker running this code //for Progress Updates and Cancelation checking BackgroundWorker thisWorker = (BackgroundWorker)sender;

//更多代码省略
}

//Further code omitted }


private void btn_OkApplyCancel(object sender, ButtonClickEvent args e){
  if(sender == btnOK || sender == btnApply)
    //apply the settings
  if(sender == btnOk || sender == btnCancel)
    //Close this dialog
}


这篇关于按钮的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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