I have a web form that instantiates a class from within its default web page. The class implements session data, as does the web page, but I'm struggling to get the session to remain constant.
Each time the page reloads, it re-instantiates the class, and thus the session, rendering the entire concept of my session moot.
How does one implement a session without instantiating it in the page itself, or any classes that are instantiated from the page? Or have I got the wrong idea?
For reference, here is the page and sub-class. Where you see "..." some unnecessary code has been omitted:
Sub class:
public class invoiceHandler
{
public HttpContext sessionContext = HttpContext.Current;
...
}
Page:
public partial class _Default : Page
{
Program.invoiceHandler handler = new Program.invoiceHandler();
...
protected void updateactionsGridBind()
{
handler.sessionContext = HttpContext.Current;
try
{
invGrid.Columns[7].Visible = false;
invGrid = (GridView)handler.sessionContext.Session["editaction"];
...
}
...
}
...
protected void saveButton_Click(object sender, EventArgs e)
{
handler.sessionContext = HttpContext.Current;
invGrid.EditIndex = -1;
string kinvConv = invGrid.Rows[0].Cells[0].Text;
handler.sessionContext.Session["editaction"] = invGrid;
tools.i = kinvConv;
tools.ToInt();
handler.sessionContext.Session["kinv"] = tools.j;
handler.sessionContext.Session["<REDACTED>"] = invGrid.Rows[0].Cells[1].Text;
handler.sessionContext.Session["sup"] = invGrid.Rows[0].Cells[2].Text;
handler.sessionContext.Session["supn"] = invGrid.Rows[0].Cells[3].Text;
handler.sessionContext.Session["net"] = invGrid.Rows[0].Cells[4].Text;
handler.sessionContext.Session["vat"] = invGrid.Rows[0].Cells[5].Text;
handler.sessionContext.Session["date"] = invGrid.Rows[0].Cells[6].Text;
OnUpdate(sender, e);
}
...
}
It is at the point of savebutton_click
that the session appears to lose its data.