Found a way of doing this:
Step 1: Create a Base User Control and define Delegates and Events in this control.
Step 2: Create a Public function in the base user control to Raise Events defined in Step1.
'SourceCode for Step 1 and Step 2
Public Delegate Sub UpdatePageHeaderHandler(ByVal PageHeading As String)
Public Class CommonUserControl
Inherits System.Web.UI.UserControl
Public Event UpdatePageHeaderEvent As UpdatePageHeaderHandler
Public Sub UpdatePageHeader(ByVal PageHeadinga As String)
RaiseEvent UpdatePageHeaderEvent(PageHeadinga)
End Sub
End Class
Step 3: Inherit your Web User Control from the base user control that you created in Step1.
Step 4: From your Web User Control - Call the MyBase.FunctionName that you defined in Step2.
'SourceCode for Step 3 and Step 4
Partial Class DerievedUserControl
Inherits CommonUserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyBase.PageHeader("Test Header")
End Sub
End Class
Step 5: In your page, Load the control dynamically using Page.LoadControl and Cast the control as the Base user control.
Step 6: Attach Event Handlers with this Control.
'SourceCode for Step 5 and Step 6
Private Sub LoadDynamicControl()
Try
'Try to load control
Dim c As CommonUserControl = CType(LoadControl("/Common/Controls/Test.ascx", CommonUserControl))
'Attach Event Handlers to the LoadedControl
AddHandler c.UpdatePageHeaderEvent, AddressOf PageHeaders
DynamicControlPlaceHolder.Controls.Add(c)
Catch ex As Exception
'Log Error
End Try
End Sub