share enum between pages?

  • Thread starter Thread starter oaksong
  • Start date Start date
O

oaksong

I've got an enum in a code behind page. It's set as public enum. How
do I access it from another page?

tia
Chris
 
The same way as you would anything else that you want to access from other
pages. Just make sure it is not declared as part of the class for the page,
it can be easy to accidentally make an enum part of the page when you don't
want to. Or if you would like you can simply stick it in a separate file,
this might help you keep it organized as not being part of the codebehind.
 
this is a bad practice. pages should not access each other. the proper
way is to move the enum to a class file in the app code folder.

-- bruce (sqlwork.com)
 
this is a bad practice. pages should not access each other. the proper
way is to move the enum to a class file in the app code folder.

-- bruce (sqlwork.com)

I have a class file in the app code folder. I put the enum into that
file. When I tried to reference it from a codebehind page it produced
an error.
 
I have a class file in the app code folder. I put the enum into that
file. When I tried to reference it from a codebehind page it produced
an error.

What was the error? (nobody can help you if you just say "an error")
 
What was the error? (nobody can help you if you just say "an error")- Hide quoted text -

- Show quoted text -

The enum is named 'cpage'.
The error is: error BC30451: Name 'cPage' is not declared.
 
The enum is named 'cpage'.
The error is: error BC30451: Name 'cPage' is not declared.

The error means (I'm pretty sure) that the enum is not in scope.
Without code, It's hard to diagnose. Here are some tips:

1. Is the enum inside of a class and/or namespace?
1.1 If in a class, is it declared "Public"?
1.2 If in a namespace, is the namespace imported in the page that you
are attempting to access it?

Note: If you do end up finding the problem, make sure you post it so
other people know the fix.
 
oaksong wrote :
The enum is named 'cpage'.
The error is: error BC30451: Name 'cPage' is not declared.

Are you using C#? That is case-sensitive, so "cpage" and "cPage" are
different things.

Hans Kesting
 
The error means (I'm pretty sure) that the enum is not in scope.
Without code, It's hard to diagnose. Here are some tips:

1. Is the enum inside of a class and/or namespace?
1.1 If in a class, is it declared "Public"?
1.2 If in a namespace, is the namespace imported in the page that you
are attempting to access it?

Note: If you do end up finding the problem, make sure you post it so
other people know the fix.

The reference was out of scope. I needed to import my enums class.
Thanks!
 
Back
Top