Re: Accessing USER CONTROL which is inside Masterpage through Another USER Control inside normal page. -
11-13-2006
, 08:35 AM
Some may suggest you do a Master.FindControl to get the master pages
label control to set its properties directly.
But maybe put a property in the master page that in turn sets a
property on its user control that then sets the label controls text.
And also have the button web control raise an event when the status
changes and in its pages handler for that call the master pages
property let.
That way the interaction is between the control and the page, the page
and it's master, and the master and it's control, and not directly
between the two controls.
So in the button user control
Public Event StatusChanged(ByVal s As String)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent StatusChanged(Guid.NewGuid.ToString)
End Sub
And in the page that contains it.
Protected Sub WebUserControl1_StatusChanged(ByVal s As String)
Handles WebUserControl1.StatusChanged
Dim mp As TheMasterPage = Me.Master
mp.NewStatus = s
End Sub
And in the master page.
Public WriteOnly Property NewStatus() As String
Set(ByVal value As String)
WebUserControl2_1.StatusText = value
End Set
End Property
And in the label user control.
Public WriteOnly Property StatusText() As String
Set(ByVal value As String)
Label1.Text = value
End Set
End Property
It may seem like a lot of code up front but going forward any page can
set the status with just this.
Dim mp As TheMasterPage = Me.Master
mp.NewStatus = "Whatever"
This will have to be changed to use an interface that all master pages
implement if you ever get around to wanting to change the master page
of the site on the fly. |