加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 用户控制事件

发布时间:2020-12-15 08:14:53 所属栏目:百科 来源:网络整理
导读:我有一个用户控件,其中包含一个名为upload的按钮.按钮单击事件如下所示: protected void btnUpload_Click(object sender,EventArgs e){ // Upload the files to the server} 在存在用户控件的页面上,在用户点击上传按钮后,我想在用户控件中执行按钮点击事件
我有一个用户控件,其中包含一个名为upload的按钮.按钮单击事件如下所示:
protected void btnUpload_Click(object sender,EventArgs e)
{
  // Upload the files to the server
}

在存在用户控件的页面上,在用户点击上传按钮后,我想在用户控件中执行按钮点击事件代码后立即执行某些操作.如何在完成工作后点击Click事件?

解决方法

您必须在用户控件中创建一个事件,例如:
public event EventHandler ButtonClicked;

然后在你的方法中激活事件……

protected void btnUpload_Click(object sender,EventArgs e)
{
   // Upload the files to the server

   if(ButtonClicked!=null)
      ButtonClicked(this,e);
}

然后,您将能够附加到用户控件的ButtonClicked事件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读