Danny
Danny

Reputation: 601

ASPX page loading data from last session

I'm creating a C# application with a ASP.net frontend, however I'm having a problem at the moment. I want to the user to enter some information, which once submitted, will be displayed within a listbox on the page which works fine. However, once I close the page, stop debugging the program and run it again - the information is still displayed but I want it to start off blank. Here if the ASPX page that I think if causing the issue, it's driving me mad.

public partial class CarBootSaleForm : System.Web.UI.Page, ISaleManagerUI
{
    private SaleList saleList; 

    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack && Application["SaleList"] != null)
        {
            LoadData();
        }
        else
        {
            saleList = (SaleList)Application["SaleList"];
        }

        if (saleList != null)
        {
            UpdateListbox();
        }

    }

    private void UpdateListbox()
    {
        lstSales.Items.Clear();

        if (saleList != null)
        {
            for (int i = 0; i < saleList.Count(); i++)
            {
                lstSales.Items.Add(new ListItem(saleList.getSale(i).ToString()));
            }
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Application.Lock();
        Application["SaleList"] = saleList;
        Application.UnLock();

        Response.Redirect("AddSaleForm.aspx");
    }

}

Forget the LoadData() within the page load as it's not actually loading anything at the moment :)

Any help is really appreciated!

Upvotes: 0

Views: 284

Answers (2)

udog
udog

Reputation: 1536

The variables stored in Application state are not flushed unless you restart the web server, so you will need to use the iisreset commmand (on command-line) if you are using IIS, or you will need to stop the ASP.NET web server (use the tray icons) after each debugging session.

Upvotes: 1

ram2013
ram2013

Reputation: 505

if it is not postback you can add Session.Abandon(); in the else block in Page_load.

Kill Session:

How to Kill A Session or Session ID (ASP.NET/C#)

Upvotes: 0

Related Questions