473,669 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading UC variable from page. (Again... ;o)

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
Nov 19 '05 #1
4 1283
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

Nov 19 '05 #2
> 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?
It just parses the XML and gets a bunch of variables that are then used by
the other UCs on the page. It has no presentation itself at all.

I feel kind of stupid now, but it never occured to me to just use a class.
Duh. That makes the most sense. Argh! ;o)

Thanks for rattling my head and seeing that option!

To be more specific (in hopes of fully explaining this) I'll try to give a
better overview of what is going on:

We have a 'mini CMS' tool that we've built. This tool can spit out an XML
file that stores a variety of information:

- pageTitle
- contentID
- customContent
- linkName
- etc
- etc

Basically, a bunch of settings for each individual page that appears on the
site. From this XML file, we can easily build our navigation system using
some XSLT. On each page load, I want to pass the current pageID and then
have it read the other variables needed by the rest of the controls.
you can then access the values directly from the user control without any
need to "communicat e" with the page via:

VariableManager .PagePropPageTi tle


Hmm...let me think about that. That might work quite nicely.

The only catch is that this class is being used by 10 different 'template'
pages all with unique XML files, not to mention unique page IDs.

For instance, I may have this:

site1.aspx?page =12
- variablemanager class

site2.aspx?page =15
- variablemanager class

I could obviously just pass these from the page into the class, though:

getVariables(si te, page)

but then I'm looking up the information on each request...which would seem
to be a bit of a performance hit.

Is there anything wrong with using the class to pull up individual values on
each aspx page?

For instance, on site1.aspx:

pageTitle = getVariables(pa ssSiteID, passPageID)

then, dynamically load the control that uses page Title and pass it that
way?

-Darrel
Nov 19 '05 #3
> I could obviously just pass these from the page into the class, though:

getVariables(si te, page)
If it'were would probably provide an override which knows what the current
site and current page is. Actually, that information seems like it would be
useful to many controls and should easily be available. I'm doing something
similar and I use a "SiteContex t" class to hold information, the SiteContext
is a singleton which looks a lot like:

public class SiteContext{
#region Fields and Properties
private Section section;
private HttpContext context;
private int documentId;

public int DocumentId
{
get { return documentId; }
set { documentId = value; }
}
public Section Section
{
get { return section; }
set { section = value; }
}
public static SiteContext Current
{
get
{
if (HttpContext.Cu rrent.Items["SiteContex t"] == null)
{
HttpContext.Cur rent.Items.Add( contextKey, new SiteContext());
}
return (SiteContext)Ht tpContext.Curre nt.Items["SiteContex t"];
}
}
#endregion
#region Constructors
internal SiteContext()
{
context = HttpContext.Cur rent;
string[] segments = context.Request .Url.Segments;
string sectionName = GetSectionName( segments);
sectionName = sectionName.ToU pper();

documentId = Utility.ParseQu erystring("docu mentId", -1);
if (documentId != -1)
{
type = DocumentType.Do cumentViewer;
}
section = SectionUtility. GetAllSections( ).FindByPath(se ctionName);
if (section == null)
{
section = SectionUtility. GetDefaultSecti on();
}
}
}
}
You can then access this "SiteContex t" from any control/page via:
SiteContext.Cur rent.DocumentId

of course you would have a "PageId" and a "SiteId"...tend s to make your
controls "smarter" and less far more self-reliant (ie, less communication
between controls/page, since all the core pieces of info are in the
SiteContext which they can readily access).

As for your multiple site thing...I'd tie in what I've said above, but
change the GetAllValues() I provided previously to take a siteid/pageid and
cache based on that....

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:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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?
It just parses the XML and gets a bunch of variables that are then used by
the other UCs on the page. It has no presentation itself at all.

I feel kind of stupid now, but it never occured to me to just use a class.
Duh. That makes the most sense. Argh! ;o)

Thanks for rattling my head and seeing that option!

To be more specific (in hopes of fully explaining this) I'll try to give a
better overview of what is going on:

We have a 'mini CMS' tool that we've built. This tool can spit out an XML
file that stores a variety of information:

- pageTitle
- contentID
- customContent
- linkName
- etc
- etc

Basically, a bunch of settings for each individual page that appears on the site. From this XML file, we can easily build our navigation system using
some XSLT. On each page load, I want to pass the current pageID and then
have it read the other variables needed by the rest of the controls.
you can then access the values directly from the user control without
any need to "communicat e" with the page via:

VariableManager .PagePropPageTi tle


Hmm...let me think about that. That might work quite nicely.

The only catch is that this class is being used by 10 different 'template'
pages all with unique XML files, not to mention unique page IDs.

For instance, I may have this:

site1.aspx?page =12
- variablemanager class

site2.aspx?page =15
- variablemanager class

I could obviously just pass these from the page into the class, though:

getVariables(si te, page)

but then I'm looking up the information on each request...which would seem
to be a bit of a performance hit.

Is there anything wrong with using the class to pull up individual values

on each aspx page?

For instance, on site1.aspx:

pageTitle = getVariables(pa ssSiteID, passPageID)

then, dynamically load the control that uses page Title and pass it that
way?

-Darrel

Nov 19 '05 #4
This is one of those things that was so easy with ASP that has become much
more of a project than I had anticipated in .net ;o)

Thanks, Karl. I'll have to sit down with your sample code for a bit and see
if I can absorb it.

-Darrel
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6010
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to be played with - this is not the final result so please (unless it's leading to the script failure)...
5
2520
by: Peter | last post by:
Hello! I Have a problem. I try to use asp.net page-wide variable but it is not working. I declare my boolean variable (eg. bool done=false) in the same place where page's web controls are declared. However when I try to use it in a function, like if (this.done==false) { Response.Write("writing file") this.WriteFile();
4
2515
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add" button is clicked. In addition, the session variable is reset to zero when the "Empty" button is pressed. The problem is if the value is non-zero and the page is reloaded the value is incremented. It appears as if the "Add" onClick event...
12
2927
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are gen.aspx.vb and uc.ascx.vb. With simple html or self contained vb in the user control, everything is fine and dandy. So the next stage is to pass back a simple variable from the user control to the host page. I used VS.NEt to create the files.
7
6055
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should populate a series of structures of specified variable composition. I have the structures created OK, but actually reading the files is giving me an error. Can I ask a simple question to start with: I'm trying to read the file using the...
2
1846
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again (an endless loop). i thought that BinaryReader.ReadByte advanced to the next byte? i had it time out after 1000 iterations, and keeps outputting the same byte. any help appreciated, my code is below: Imports System.io
2
1158
by: Thief_ | last post by:
I'm using the following code to read in a web page as HTML: ' Download the web page using the chosen update method. Dim sr As New System.IO.StreamReader(wc.OpenRead("http://www.vbcity.com/forums/active.asp" & _ Options.UpdateMethod)) Options.UpdateMethod contains "?action=1month&page=1"
19
2298
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
9
1437
by: The Ax | last post by:
I want to read this array backwards. http://hiscore.runescape.com/index_lite.ws?player=grimmstriker Its not my site so I cant find the arrays name instead of: 1319710,847,1620107 -1,-1,-1 i want line1 = 1319710,847,1620107 line2 = -1,-1,-1
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.