Classe personalizzata per memorizzare le proprietà e di passare la sua istanza attraverso le pagine - ASP.NET
-
26-09-2019 - |
Domanda
Ho un requisito in cui ho bisogno di passare alcuni oggetti attraverso le pagine. Così ho creato una classe personalizzata con tutte le proprietà necessarie e ha creato un'istanza di esso e assegnate tutte le proprietà in modo appropriato. Ho poi messo l'oggetto nella sessione e preso l'altra pagina.
Il problema è che, anche quando si imposta il valore proprietà alla classe è venuta come nullo. Ho impostato un punto di interruzione nel getter-setter e ho visto che il valore stesso è venuta come nullo.
Codice -
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;
}
}
}
Questo è come mi sto creando un'istanza nella page1 e cercando di ottenere nel page2.
Codice Pagina1
//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();
Ma i valori non sono sempre impostato a tutti. I valori non sono di passaggio alla classe (per il setter) a tutti. Sto facendo alcun errore OOP?
Tutte le idee?
NLV
Soluzione
Stupida e sciocca. Deve essere 'valore' al posto della variabile pubblica nel setter.