I really didn’t know how to ask this question in a simple fashion.
I need to display a Client name on a page in several places and they’re not always visible at the same time.
The solution I originally had was 3 Label Controls (uxClientName1, uxClientName2 and uxClientName3) and I’d populate them in my code behind when I needed them.
uxClientName1 = CurrentClient.ClientName
A colleague suggested I use the following solution. On my page I would have this wherever I need it…
<%=DisplayClientName()%>
and in my code behind I would have this…
Protected Function DisplayClientName() As String
Return CurrentClient.ClientName
End Function
This is great because it’s doing exactly what I want with no repeated code but I don’t really understand how it works or exactly what’s going on.
Any explanations?
EDIT: This is my Client Property on the page…
Private Property CurrentClient() As Client
Get
If ViewState("CurrentClient") Is Nothing Then
' No such value in view state, take appropriate action.
ViewState("CurrentClient") = New Client
Return CType(ViewState("CurrentClient"), Client)
Else
Return CType(ViewState("CurrentClient"), Client)
End If
End Get
Set(ByVal value As Client)
ViewState("CurrentClient") = value
End Set
End Property
These are embedded code blocks.
Some uses for embedded code blocks:
Here is a list of all inline ASP.NET tags.