0

我有一个要求,我需要在页面之间传递一些对象。所以我创建了一个包含所有必需属性的自定义类,并创建了它的一个实例并适当地分配了所有属性。然后我将该对象放入会话中并将其带到另一页。

问题是,即使我将属性值设置为类,它也会为空。我在 getter-setter 中设置了一个断点,并看到该值本身为 null。

代码 -

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;
        }
    }
}

这就是我在page1 中创建实例并尝试在page2 中获取它的方式。

第1页代码

//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();

但是这些值根本没有设置。这些值根本没有传递给类(传递给 setter)。我是否犯了任何 OOP 错误?

有任何想法吗?

NLV

4

1 回答 1

0

愚蠢而愚蠢。它必须是“值”而不是 setter 中的公共变量。

于 2010-05-12T09:27:58.417 回答