[英]Event in User Control does not raise
I have a User Control that contains a grid and some buttons. 我有一个包含网格和一些按钮的用户控件。 I declare
GridAfterRowActivate
event for User Control: 我为用户控件声明
GridAfterRowActivate
事件:
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. 当我在表单构造函数中填充网格时,
GridAfterRowActivate
事件不会引发。 But when I fill grid in Form_Load
, this event works correctly. 但是,当我在
Form_Load
填充网格时,此事件将正常工作。
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
. 我想这是因为您在构造函数中填充了控件,但是直到页面的
PreInit
之后才调用控件的Init事件。 You should fill the control at the earliest on the page's Init
event. 您应该尽早在页面的
Init
事件中填充控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.