0

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!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Danny
  • 601
  • 2
  • 9
  • 11

2 Answers2

1

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.

udog
  • 1,490
  • 2
  • 17
  • 30
0

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#)

Community
  • 1
  • 1
ram2013
  • 505
  • 2
  • 9
  • 19
  • Hmm, this doesn't seem to work. The data is still there as soon as the page is opened again. – Danny Apr 23 '13 at 22:15