How do i raise an event in a usercontrol and catch it in mainpage?

前端 未结 3 446
小鲜肉
小鲜肉 2020-12-02 06:58

I have a UserControl, and I need to notify the parent page that a button in the UserControl was clicked. How do I raise an event in the UserC

3条回答
  •  难免孤独
    2020-12-02 07:41

    Just add an event in your control:

    public event EventHandler SomethingHappened;
    

    and raise it when you want to notify the parent:

    if(SomethingHappened != null) SomethingHappened(this, new EventArgs);
    

    If you need custom EventArgs try EventHandler instead with T beeing a type derived from EventArgs.

提交回复
热议问题