The solution I found to this problem is from an old article from 2002 on Code Project. Here's the link to that article ASP.NET User Controls - Notify One Control Of Changes In Other Control. After reading that article and looking through sample code, here are the following changes I made to the code above.
There are no changes to the ASPX files except the following line in the Output ASPX file should be removed.
<%@ Reference Control="~/Input.ascx" %>
First you add a new class called LabelChangeEventArgs.
Public Class LabelChangeEventArgs
Inherits EventArgs
Private _LabelStr As String
Public Property LabelText() As String
Get
Return _LabelStr
End Get
Set(value As String)
_LabelStr = value
End Set
End Property
End Class
User Control Input VB.net: You add a Delegate and use the new LableChangeEventArgs class to handle the string.
Public Delegate Sub LabelChangeEventHandler(ByVal sender As Object, ByVal e As LabelChangeEventArgs)
Partial Class UCInput
Inherits System.Web.UI.UserControl
Public Event OnLabelChanged As LabelChangeEventHandler
Protected Sub OnButtonClick(sender As Object, e As EventArgs)
Dim args As New LabelChangeEventArgs
args.LabelText = TextBox1.Text
RaiseEvent OnLabelChanged(Me, args)
End Sub
End Class
User Control Output VB.net: You make a sub to receive the args and change the label.
Public Sub LabelChange(sender As Object, args As LabelChangeEventArgs)
If args IsNot Nothing Then
Label1.Text = args.LabelText
End If
End Sub
and in the parent page codefile you wire up the controls together.
Protected Sub WireHandles() Handles Me.Init
AddHandler UCInput1.OnLabelChanged, AddressOf UCOutput1.LabelChange
AddHandler UCInput2.OnLabelChanged, AddressOf UCOutput2.LabelChange
End Sub
Here's a download link to the src files Link