471,317 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Hashtable not working

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

Nov 26 '05 #1
4 1398
Jeff User wrote:
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".

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 26 '05 #2
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jeff User" wrote:
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

Nov 26 '05 #3
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

On Sat, 26 Nov 2005 21:42:58 GMT, Jeff User <je*******@hotmail.com>
wrote:
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


Nov 27 '05 #4
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
On Sat, 26 Nov 2005 21:42:58 GMT, Jeff User <je*******@hotmail.com>
wrote:
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


Nov 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by francois | last post: by
5 posts views Thread by francois | last post: by
reply views Thread by mnmnm1951 | last post: by
2 posts views Thread by D. Shane Fowlkes | last post: by
10 posts views Thread by SK | last post: by
2 posts views Thread by Scott M. Lyon | last post: by
9 posts views Thread by nithya4u | last post: by
2 posts views Thread by Bruce | last post: by
reply views Thread by rosydwin | last post: by

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.