Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

ASP.NET - Having issues with value in a class - not changing

I have a Session["AccessKey"].  I am passing the value to a Class "CustomerAccessKey".  Then I call FileList.getFiles to bind it to the repeater.  In this class I need the "CustomerAccessKey" value.  

When i run the website the first time and use key "1234" it gets the data correctly.  
I log out.  
Log back in and have key = "3456".
I see it being set in "CustomerAccessKey" as "3456" but in FileList.GetFiles the CustomerAccessKey = "1234".  

How do I fix?

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
         //Access Key
         CustomerAccessKey.getCustomerAccessKey = Session["AccessKey"].ToString();
         //Get Files
         rptFiles.DataSource = FileList.getFiles;
         rptFiles.DataBind();
    }
}

Open in new window


public class FileList
{
    static FileList()
    {
        IMDRTransferService _getFiles = new MDRTransferServiceClient();

        getFiles = new List<Files>();
        foreach (var files in 
                _getFiles.CustomerFiles(CustomerAccessKey.getCustomerAccessKey))
        {
            getFiles.Add(new Files() { FileName = files.FileName, 
                                                        DisplayName = files.DisplayName });
         }                   
    }
    public static List<Files> getFiles { get; set; }
 }

public class Files
{
    public string FileName { get; set; }
    public string DisplayName { get; set; }
}

Open in new window


public class CustomerAccessKey
{
    public static string getCustomerAccessKey { get; set; }
}

Open in new window

Avatar of BuggyCoder
BuggyCoder
Flag of India image

This is precisely because you are using static constructor in FileList Type, which will be called only once during entire application and that is at the time of AppDomain Creation.

When you make the call to FileList For very first time(ie. during first login with 1234 id), the constructor gets called and file list is loaded.

Any furthur calls to get files will never call the static constructor.

If you want to load files again, create a method in the FileList Class namely getFiles and return FilList for this new accesskey....
Avatar of CipherIS

ASKER

remove the keyword static?  can you give me a code sample of how to fix?
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its not working.  Now its worse.  i'm not receiving any data.
I don't know what happened but it seems to be working now.  Thx