How to Raise an Event in a Custom Control

By bryan tugade

We can raise an event in a custom control and use that event to trigger it when a control is clicked.

1. create a WebUserControl

2. Add button in your WebUserControl

3. Put this code in code behind

Imports System

Partial Class events_WebUserControl
    Inherits System.Web.UI.UserControl
    Public Event myEvent(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        RaiseEvent myEvent(sender, e)
    End Sub
  
End Class

4. Add the created WebUserControl in your page.

5. Find the method in the code behind.

i.e.

Thats it. Hope this will help you.

How to Raise an Event in a Custom Control  (688 Views)