473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Emulating variables static to the page

This is a Framework 1.x question.

I'm creating a class that generates HTML element IDs (<foo id='id1'>
for example) and need the element IDs to be unique across the page. The
reusable class can't access ViewState since it is protected. Note there
can be multiple instances of the class rendered on the page.

What I need is a way to create an ID that is unique to that page. It
does not matter if the IDs that get created the next time thru are the
same. A static inside my class is one way to go, but these numbers just
keep getting bigger and bigger, and id917901 10 times in my page is
just ugly.

The Cache object is another way to go. For now I am messing around with
storing the last used UID in:

ASPUtils.Page.Cache[Guid +
HttpContext.Current.Request.RawUrl.ToString() +
HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value +
HttpContext.Current.Timestamp.ToString()]

where Guid is static to the reusable class. This keeps the numbers from
growing too large I think, since the cache entry is personalized to the
user/page/time of request. I have not read up on caching in awhile, but
I could/will set a very short expiration so this gets expunged quickly,
thus saving memory. I'd also need to conditionally include the session
ID just in case it is not set. Or maybe there is a way I can remove my
item from the cache by attaching to some page render event, thus
ensuring it is cleared for the next user request. I'll have to look
into this.

The primary goal of my post: I wanted to see if there is a more
"built-in" way to get/set something that is static across an instance
of the current page. Anything?

Thanks,
-Mike

Nov 19 '05 #1
2 1211
public class MyPage
{

private int counter;

... the rest of your page goes here
}

Isn't that enough?
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #2
No. This is within a generic WebControl derived class that has no say
over the Page class that uses it.

-Mike

Nov 19 '05 #3

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

Similar topics

2
by: Bart | last post by:
Hi there, Since you've all told me that frames ar evil, I'm planning to disguard frames in favour of CSS "pseudo-frames" for my personal website. While trying to "emulate frames" (that is I...
2
by: Earl Teigrob | last post by:
I am programming ASP.NET using C#. I have been accessing static variables accross my entire application but now need to change some of the static variables that are session specific to instance...
4
by: Wayne | last post by:
Hi, I'm new to .NET and have a question about the use of static variables vs. session variables in a web form in C#. Instead of using a session variable to hold a string to persist during...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
5
by: Tom Pearson | last post by:
What is the scope of static variable when programming in ASP.NET? For example I have a control class that uses static callbacks so that another window can pass a list of items to it. The control...
9
by: Randy | last post by:
Hello, I'm having a strange problem. I've got a .NET web app which uses Session variables. Sometime, not all the time, they get cross threaded...that is...one user will have another user's Session...
7
by: Ray | last post by:
Hello, What do you think about emulating private variables for a class this way? function Something() { var private; Something.prototype.getPrivate = function() { return private; }...
16
by: RB | last post by:
Hi clever people :-) I've noticed a lot of people stating not to use static variables with ASP.NET, and, as I understand it, the reason is because the variable is shared across user sessions -...
4
by: Wolfgang Draxinger | last post by:
If you know languages like Python or D you know, that nested functions can be really handy. Though some compilers (looking at GCC) provide the extension of nested functions, I wonder, how one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.