gpt4 book ai didi

c# - 用户控制点击事件

转载 作者:太空狗 更新时间:2023-10-30 00:36:17 29 4
gpt4 key购买 nike

在用户控件中,我有一个自定义按钮。我在 aspx 页面上使用这个用户控件。单击用户控件中的按钮时,应清除 aspx 页面中的复选框和标签。你能告诉我如何完成这个吗?

最佳答案

在您的用户控件中,您需要创建一个公共(public)事件处理程序

public event EventHandler UpdateParentPage;

在你的用户控件的按钮点击事件中,放置

protected void btn_Click(object sender, EventArgs e)
{
if (this.UpdateParentPage != null)
UpdateParentPage(sender, e);
}

在您的父页面代码后面,为您的用户控件设置事件处理程序:

userControl.UpdateParentPage+= new EventHandler(userControl_UpdateParentPage);

然后,在您的父页面上实现新的事件处理程序:

protected void userControl_UpdateViewState(object sender, EventArgs e)
{
//clear your checkboxes and label here
}

关于c# - 用户控制点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2381732/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com