Shared Class

I am trying to store some user information in my web project. The user information needs to be session specific so I have done the following which isnt working.

  • Created a class in a global module called “clsUserInfo” - the global module is called “GlobalModule”
  • Under the class I have created properties called “name”, “age”, “email”

On a web page I am trying to set the users name so that it can be used on other web pages and throughout the session. So I am doing the following:

  • = “fred”
  • = “fred”

Neither of the above work so I am now confused as to what I am doing wrong.

You need to refer to an instance of the class in the Session object.

Create a property in the Session object: UserInfo As clsUserInfo

In the Open event handler of the Session object assign your values:

UserInfo = New clsUserInfo

Now you can refer to the instance. In the Session class, you can just refer to UserInfo since it is a property. Outside of Session, qualify it with Session.UserInfo.

Also, the Module serves no role here. You might choose to create your class in a Module, but you don’t need to do it that way. Just create the class at the main level of the project.

Thanks Paul, that now makes sense. Kem, what do you mean by the main level of the project?

I took a screenshot to illustrate:

I created MyClass at the top level of the project. I recommend folders, not modules, as a way to organize your various classes.

Thanks Kem that is a great idea, I will tweak my project now to use folders for my classes.