Hashtable not working

J

Jeff User

Hi
I thought I would try a hashtable for storing key and title value
pairs. For instance,

public class MyBasePAgeClass
{
Hashtable TitleHash = new Hashtable();
........
private void Page_Load(object sender, System.EventArgs e)
{
TitleHash.Add("home","Home");
TitleHash.Add("dbs","Create / Drop Databases");
.........

Then, later on, I evaluate the key (sent back when next page is
requested).
if (key ="dbs") then display the title
"Create / Drop Databases", etc..

This is a web app (asp/c#).
I am using 1 aspx.cs file as a base class for all my other web pages.
It contains common functions, etc..
So, I declare and populate the table in the base class and therefore
it is accessible to all web pages. Now, this means that the table has
to be rebuilt everytime a post is made and a new page generated.

1) Is this the best way to make a structure like this available to all
web pages?

There will probably be around 15 or 20 entries.

Is there a benefit to using hashTable over 2D string array or would an
array be better?

Thanks
Trying to improve
Jeff
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

Jeff said:
Hi
I thought I would try a hashtable for storing key and title value
pairs. For instance,

What exactly is your question?
- is it wether what you're doing is the best way or if there's a better
one? (judging by the text)
- is it wether Hashtable is actually doing what its supposed to do?
(judging by the subject of the post)

What exactly is the problem you're trying to solve? It would help to
know more about what you're doing before a definite answer can be given.

The best answer I can give from your current problem "description" is
"it depends".
 
G

Guest

Jeff,
It "sounds" like from what you are saying that you assume a Hashtable in a
MasterPage class is static, and that is not necessarily true.
You could certainly add a static Hashtable to your Global class, and it
would be available from all pages, or you can use Session or Cache, whichever
better suits your business logic. With only 15 or 20 items to store, it
really would not make much difference whichever you choose to use.
Peter
 
J

Jeff User

Sorry folks, The subject was not really correct for this post. I had
started out with a problem, solved it, and then was just wondering
about the issues that I listed. I forgot to change the topic.

Basically, as far as HashTable vs 2d array:
what are the benefits of one over the other? When to use which one?

And, the other Q was related to my means of having common code for all
web pages. Sorry, I guess this is a different topic, technically, but
it is what I am trying to do with the hash table.

Thanks again.
Jeff
 
J

Jeff User

Sorry folks, The subject was not really correct for this post. I had
started out with a problem, solved it, and then was just wondering
about the issues that I listed. I forgot to change the topic.

Basically, as far as HashTable vs 2d array:
what are the benefits of one over the other? When to use which one?

And, the other Q was related to my means of having common code for all
web pages. Sorry, I guess this is a different topic, technically, but
it is what I am trying to do with the hash table.

Thanks again.
Jeff
 

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

Top