if i have an application, how can i Keep tract an ID within the whole application??

  • Thread starter Thread starter Jason
  • Start date Start date
just that case is
after login, i will have an ID from that user
I want to keep track that userID within all the form
how can i do??
 
Create a class with a public static property. Then all classes can set and
get the value using the syntax className.propertyName.

Here's an example:

public class SessionData
{
private static string userID = "";
public static string UserID
{
get { return userID; }
set {userID = value; }
}
}

Now you can get the value by calling: SessionData.UserID = userID;
And read the value via: userID = SessionData.UserID;

Alternatively, you could build this into the form's definition by creating a
stateful base class form that encapsulates the state information:

public class StateForm : System.Windows.Forms.Form
{
private static string userID = "";
public static string UserID
{
get { return userID; }
set {userID = value; }
}
}

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Back
Top