Ok so I have created a page where the user enters their details then they click a button which produces their results in a ListBox. However what I want to do is when the user clicks the button it produces the results on another page in a Listbox. I have been able to get the session to work with a textbox but not a listbox.
Code:
page1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
List<string> myList;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
myList = new List<string>(); // first time it loads is not a postBack
Session["listSession"] = myList; // stick the list in a session variable
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
myList = (List<string>)Session["listSession"]; // gets the list out of session
myList.Add(TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text);
foreach (var inputString in myList)
{
ListBox1.Items.Add(inputString + "");
}
}
}
}
Any help would be appriciated: