プロパティを格納し、ページ間でそのインスタンスを渡すためにカスタムクラス - ASP.NET

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

  •  26-09-2019
  •  | 
  •  

質問

私は私がページ間でいくつかのオブジェクトを渡す必要がある要件をしました。必要とそのインスタンスを作成し、適切なすべてのプロパティを割り当てられたすべてのプロパティを持つカスタムクラスを作成した私はそう。私は、その後のセッションでそのオブジェクトを入れて、それを他のページを取っています。

問題は、私はクラスにプロパティ値を設定した場合でも、それがnullとして来ているということです。私は、値自体が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;
        }
    }
}

これは私がページ1でインスタンスを作成し、PAGE2でそれを取得しようとしている方法です。

Page1のコード

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

しかし、値はすべてのセットを取得されていません。値は、すべての(セッターに)クラスに渡されていません。私はOOPの失態を作るのですか?

任意のアイデア?

NLV

役に立ちましたか?

解決

愚かと愚かな。それは「の値」の代わりのセッターでパブリック変数にする必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top