Darrel,
Don't mean to keep jumping in and potentially causing other points of views
to be skipped. Additionally, I can't say I fully remember the context of
our conversation. having said that, to specifically answer your question,
there's nothing wrong with loading your controls (even all of them)
dynamically. You'll incur a performance hit, but more than likely something
you won't notice...AND it'll often be the only way you can do something.
Having said that, perhaps we discussed this previously, but it seems to me
that maybe getVariables.ascx shouldn't be a user control. Does it display
anything or does it simply get variables from XML and make them available?
If it doesn't have a presentation component (and from your description it
doesn't), you really should be making us of a class, perhaps:
VariableManager.vb (or .cs depending on what poison you prefer). Even if
getVariables.ascx DOES have a presentation element, the part which interacts
with the XML file more than likely belongs in a class, in your business
layer, not your presentation.
Public NotInheritable Class VariableManager
Private Sub New()
End Sub
Public Shared ReadOnly Property PagePropPageTitle() As String
Get
Return GetPropertyByName("PagePropPageTitle")
End Get
End Property
Public Shared Function GetPropertyByName(ByVal name As String) As String
Dim values As NameValueCollection = GetAllValues()
Return values(name)
End Function
Private Shared Function GetAllValues() As NameValueCollection
Dim values As NameValueCollection =
CType(HttpRuntime.Cache("AllValues"), NameValueCollection)
If values Is Nothing Then
'retrieve values from xML file and put them in the values
HttpRuntime.Cache.Insert("AllValues", values, New
System.Web.Caching.CacheDependency("XML_FILE_PATH" ))
End If
Return values
End Function
End Class
you can then access the values directly from the user control without any
need to "communicate" with the page via:
VariableManager.PagePropPageTitle
Basically the GetAllValues parses the XML file and stores the values into a
NameValueCollection (key => value) and uses caching so it doesn't always
have to parse it. The NameValueCollection is wrapped inside easy-to-use
methods, alal PagePropertyPageTitle.
Hope this helps :)
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"darrel" <no*****@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP14.phx.gbl...
Karl has helped me in the past in regards to communicating between
controls and pages:
http://www.openmymind.net/communication/index.html#3.1
I ended up going down the interfaces path and actually got that working
fairly well, but, then, in the end, decided that was overkill and that it
would perhaps make more sense to start over using a much more simpler
communication between pages.
So, this is what I have:
getVariables.ascx
otherControl.ascx
page.aspx
getVariables reads an xml file and sets a variety of strings. We'll use
this generic one:
public pagePropPageTitle as string
'logic to read xml and set the value
on page.aspx, I want to get the pagePropPageTitle value and then send that
onto otherControl.ascx
Is there a way to grab that value directly? I can't just go
getVariables.pagePropPageTitle because that isn't declared. Is there
another way to go about this?
Looking at the above tutorial, it talks about how to do this using
dynamically loaded controls. Is that the only way? If so, is there
anything wrong with dynamically loading all of your controls via the codebehind?
-Darrel