Global variable via static class???

Last post 05-16-2008 1:55 AM by baur__. 6 replies.

Sort Posts:

  • Global variable via static class???

    05-15-2008, 7:45 AM
    • Loading...
    • baur__
    • Joined on 04-28-2008, 10:23 PM
    • Almaty
    • Posts 13
    Hi all
    I’d like to save info about user via global variable (static class) without any providers

    App_Code\GData.cs
    -----------------

    using System;
    using System.Data;

    public class UserInfo
    {
    private static string pin;
    public static string Pin
    {
    get { return pin; }
    set { pin = value; }
    }
    private static string fio;
    public static string Fio
    {
    get { return fio; }
    set { fio = value; }
    }
    }
    public class QData
    {

    public class GData
    {
    public static void SetUserInfoPIN(string pin)
    {
    UserInfo.Pin = pin;
    }
    public static string GetUserInfoPIN()
    {
    return UserInfo.Pin;
    }

    }


    Is it possible??? It doesn’t be overwritten with entrance another user? So I’m using static class?

    set

    GData.SetQDataPIN(”111”);break;
    GData.SetQDataUSERNAME(”User”); break;

    }

    get

    done.Parameters["Done"].Value = GData.GetQDataCOND();
    done.Parameters["id_zh"].Value = GData.GetQDataIDZ();

    }

    Is here other ways to save global variables???
    Filed under:
  • Re: Global variable via static class???

    05-15-2008, 8:16 AM
    Answer
    • Loading...
    • Mahadeomatre
    • Joined on 04-23-2007, 11:00 AM
    • Pune, India
    • Posts 228

    static variables are overwritten whn another user login to system.

    so i think u can use any state managment method to store ur global variables depending upon ur application's  security.

    Thanks,
    Mahadeo

    -----------------------------------------------
    Best is Not the END point, but a starting point for Innovation
    ------------------------------------------------
    Remember to mark posts as the "Answer" to help future users.
  • Re: Global variable via static class???

    05-15-2008, 8:24 AM
    • Loading...
    • baur__
    • Joined on 04-28-2008, 10:23 PM
    • Almaty
    • Posts 13
    yes, you're right I just checked it;
    is here another way to save like this informations
    
    maybe just remove 'static' and work with copy of instance
  • Re: Global variable via static class???

    05-15-2008, 8:39 AM
    Answer
    • Loading...
    • Mahadeomatre
    • Joined on 04-23-2007, 11:00 AM
    • Pune, India
    • Posts 228

    yes.. remove static and work with copy of instance..

    Thanks,
    Mahadeo

    -----------------------------------------------
    Best is Not the END point, but a starting point for Innovation
    ------------------------------------------------
    Remember to mark posts as the "Answer" to help future users.
  • Re: Global variable via static class???

    05-16-2008, 12:40 AM
    • Loading...
    • baur__
    • Joined on 04-28-2008, 10:23 PM
    • Almaty
    • Posts 13
    app_code\GData.cs
    public class UserInfo
    {
        private  string fio;
        public  string Fio
        {
            get { return fio; }
            set { fio = value; }
        }
    }
    
    public class GData
    {
    
        public void SetUserInfoFIO(string fio)
        {
            UserInfo ui = new UserInfo();
            ui.Fio = fio;
        }
    
        public string GetUserInfoFIO()
        {
            UserInfo ui = new UserInfo();
            return ui.Fio;
        }
    }
    
    default.cs
    GData gd = new GData();
            gd.SetUserInfoFIO("User");
            TextBox1.Text = gd.GetUserInfoFIO();
    
    it doesn't work, shows nothing in textbox   :(
    
    why???
    
  • Re: Global variable via static class???

    05-16-2008, 1:52 AM
    • Loading...
    • baur__
    • Joined on 04-28-2008, 10:23 PM
    • Almaty
    • Posts 13
    fault was here:
    public class UserInfo
    {
        private  string fio;
        public  string Fio
        {
            get { return fio; }
            set { fio = value; }
        }
    }
    
    public class GData
    {
        UserInfo ui = new UserInfo(); //<<<<<
  • Re: Global variable via static class???

    05-16-2008, 1:55 AM
    • Loading...
    • baur__
    • Joined on 04-28-2008, 10:23 PM
    • Almaty
    • Posts 13
    but it works within one method only:
    public partial class _Default : System.Web.UI.Page 
    {
        GData gd = new GData();
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            gd.SetUserInfoFIO("User");
            TextBox2.Text = gd.GetUserInfoFIO();//Ok!!! :)
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox2.Text = gd.GetUserInfoFIO();//Fail, shows nothing :(
        }
    }
    
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter