Custom Class to store the properties and to pass its instance across the pages - ASP.NET

StackOverflow https://stackoverflow.com/questions/2817434

  •  26-09-2019
  •  | 
  •  

문제

I've a requirement where i need to pass some objects across the pages. So i created a custom class with all the properties required and created a instance of it and assigned all the properties appropriately. I then put that object in the session and took it the other page.

The problem is that even when i set the properties values to the class it is coming as null. I set a breakpoint in the getter-setter and saw that the value itself is coming as null.

Code -

public class GetDataSetForReports
{
    private Table m_aspTable;
    private int m_reportID;
    private string m_accountKey;
    private string m_siteKey;
    private string m_imUserName;

    /// <summary>
    /// Asp Table containing the filters
    /// </summary>
    public Table aspTable
    {
        get
        {
            return m_aspTable;
        }
        set
        {
            m_aspTable = aspTable;
        }
    }

    /// <summary>
    /// Report ID
    /// </summary>
    public int reportID
    {
        get
        {
            return m_reportID;
        }
        set
        {
            m_reportID = reportID;
        }
    }

    /// <summary>
    /// All the accounts selected
    /// </summary>
    public string accountKey
    {
        get
        {
            return m_accountKey;
        }
        set
        {
            m_accountKey = accountKey;
        }
    }

    /// <summary>
    /// All the sites selected
    /// </summary>
    public string siteKey
    {
        get
        {
            return m_siteKey;
        }
        set
        {
            m_siteKey = siteKey;
        }
    }

    /// <summary>
    /// Current User Name
    /// </summary>
    public string imUserName
    {
        get
        {
            return m_imUserName;
        }
        set
        {
            m_imUserName = imUserName;
        }
    }
}

This is how i'm creating an instance in the page1 and trying to get it in the page2.

Page1 Code

//Add the objects to the GetDataSetForReports Class
GetDataSetForReports oGetDSForReports = new GetDataSetForReports();
oGetDSForReports.aspTable = aspTable;
oGetDSForReports.reportID = iReportID;
oGetDSForReports.accountKey = AccountKey;
oGetDSForReports.siteKey = Sitekey;
oGetDSForReports.imUserName = this.imUserName.ToString();

But the values are not getting set at all. The values are not passing to the class (to the setter) at all. Am i making any OOP blunder?

Any ideas?

NLV

도움이 되었습니까?

해결책

Stupid and silly. It has to be 'value' instead of the public variable in the setter.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top