D
dawg1998
I am trying to access a label located in a MasterPage from a class
located in my application's App_Code folder. The problem seems to be
that the class cannot communicate with the MasterPage due to a lack of
reference to it. How do I supply a reference to the class so that it
can populate the label? My code is below...
*The reason I am doing it this way, is that I want the typical code
used to supply a string to the MasterPage label to be hidden away in
case I change it later on. Using an object to send a string to the
class allows me to do this without committing each and every page to a
specific method.*
`````````````````````````````````````````````````````````````
1) So, in my MasterPage I set up a simple Label control:
<asp:label id="lblLabel" runat="server" />
2) In a class stored in App_Code I set up a procedure to populate the
label in the MasterPage:
Public Namespace CustomClasses
Public Class MessageMaker
Public Sub CreateMessage(ByVal strMessage As String)
Dim lblError As Label
lblError = Master.FindControl("lblLabel")
lblError.Text = strMessage
End Sub
End Class
End Namespace
In a content page, I want a procedure to create that creates a message
in the MasterPage label. This will be used for all system messages sent
to the user.
Dim objMessage As New CustomClasses.MessageMaker()
objMessage.CreateMessage("This is a Test")
located in my application's App_Code folder. The problem seems to be
that the class cannot communicate with the MasterPage due to a lack of
reference to it. How do I supply a reference to the class so that it
can populate the label? My code is below...
*The reason I am doing it this way, is that I want the typical code
used to supply a string to the MasterPage label to be hidden away in
case I change it later on. Using an object to send a string to the
class allows me to do this without committing each and every page to a
specific method.*
`````````````````````````````````````````````````````````````
1) So, in my MasterPage I set up a simple Label control:
<asp:label id="lblLabel" runat="server" />
2) In a class stored in App_Code I set up a procedure to populate the
label in the MasterPage:
Public Namespace CustomClasses
Public Class MessageMaker
Public Sub CreateMessage(ByVal strMessage As String)
Dim lblError As Label
lblError = Master.FindControl("lblLabel")
lblError.Text = strMessage
End Sub
End Class
End Namespace
In a content page, I want a procedure to create that creates a message
in the MasterPage label. This will be used for all system messages sent
to the user.
Dim objMessage As New CustomClasses.MessageMaker()
objMessage.CreateMessage("This is a Test")