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.as cx 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.as cx 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 PagePropPageTit le() As String
Get
Return GetPropertyByNa me("PagePropPag eTitle")
End Get
End Property
Public Shared Function GetPropertyByNa me(ByVal name As String) As String
Dim values As NameValueCollec tion = GetAllValues()
Return values(name)
End Function
Private Shared Function GetAllValues() As NameValueCollec tion
Dim values As NameValueCollec tion =
CType(HttpRunti me.Cache("AllVa lues"), NameValueCollec tion)
If values Is Nothing Then
'retrieve values from xML file and put them in the values
HttpRuntime.Cac he.Insert("AllV alues", values, New
System.Web.Cach ing.CacheDepend ency("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 "communicat e" with the page via:
VariableManager .PagePropPageTi tle
Basically the GetAllValues parses the XML file and stores the values into a
NameValueCollec tion (key => value) and uses caching so it doesn't always
have to parse it. The NameValueCollec tion is wrapped inside easy-to-use
methods, alal PagePropertyPag eTitle.
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*****@hotmai l.com> wrote in message
news:ee******** ******@TK2MSFTN GP14.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.as cx
otherControl.as cx
page.aspx
getVariables reads an xml file and sets a variety of strings. We'll use
this generic one:
public pagePropPageTit le as string
'logic to read xml and set the value
on page.aspx, I want to get the pagePropPageTit le value and then send that
onto otherControl.as cx
Is there a way to grab that value directly? I can't just go
getVariables.pa gePropPageTitle 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