Event in User Control does not raise

327 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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's Init event.