Help with Global data type

  • Thread starter Thread starter Matias
  • Start date Start date
M

Matias

Hi:

I need some help, about How can I define a GLOBAL Data type in ASP.net
proyect.

thanks
 
Hi,

The easiest way is to use the Application() or Session() objects:

Application("GlobalVariableName") = "whatever you want"
Session("GlobalVariableName") = 12345

The difference between the two is that when you use Application() all users
will see whatever the variable is and when you change it they all see the
changes. With Session() the variable is unique for each user, so when you
change it for one user the other user still has the same value they had
before. Good luck! Ken.
 
Matias said:
Hi:

I need some help, about How can I define a GLOBAL Data type in ASP.net
proyect.

What kind of data type? You can just create a public class in a .cs (or .vb)
file:

MyType.cs:
public class MyType
{
private int _num;
public MyType() {}
public int Num
{
get {return _num;}
set {_num = value;}
}
}

In MyPage.aspx:

private MyType _mine = new MyType();

....

private void Page_Load(object sender, EventArgs e)
{
_mine.Num = 1;
}

private void Button_Click(object sender, EventArgs e)
{
int i = _mine.Num; // i is now 1
}

You can use the same type on a different page, or use multiple instances of
it on a single page, or whatever, just like it was any other data type.

John Saunders
 
Back
Top