用户控件中的事件不会引发
我有一个包含网格和一些按钮的用户控件。 我为用户控件声明 GridAfterRowActivate 事件:
public event EventHandler GridAfterRowActivate;
private void Grid_AfterRowActivate(object sender, EventArgs e)
{
if (GridAfterRowActivate != null)
GridAfterRowActivate(sender, e);
}
我将此用户控件添加到我的表单中。当我在表单构造函数中填充网格时, GridAfterRowActivate 事件不会引发。但是当我在 Form_Load
中填充网格时,此事件正常工作。
I have a User Control that contains a grid and some buttons.
I declare GridAfterRowActivate
event for User Control:
public event EventHandler GridAfterRowActivate;
private void Grid_AfterRowActivate(object sender, EventArgs e)
{
if (GridAfterRowActivate != null)
GridAfterRowActivate(sender, e);
}
I added this User Control to my form. When I fill grid in form constructor, GridAfterRowActivate
event does not raise. But when I fill grid in Form_Load
, this event works correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这是因为您在构造函数中填充了控件,但直到页面的
PreInit
之后才调用控件的 Init 事件。您应该最早在页面的Init
事件中填充该控件。I'd imagine that it's because you filled the control in the constructor, but the control's Init event isn't called until after the page's
PreInit
. You should fill the control at the earliest on the page'sInit
event.