简体   繁体   中英

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM