Emulating variables static to the page

M

Mike Orb

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
 
M

Mike Orb

No. This is within a generic WebControl derived class that has no say
over the Page class that uses it.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top