J
Jacques Oberto
Hi All,
I am having problems retrieving a List of objects
from a Session variable on page Default2.aspx.
A "casting" error is generated. Please see code
below. Could anybody help?
Thanks,
Jacques
===============
Default.aspx.cs
===============
List<Person> people = new List<Person>();
public class Person
{
public int age;
public string name;
public Person(int age, string name)
{
this.age = age;
this.name = name;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
people.Add(new Person(50, "Fred"));
people.Add(new Person(30, "John"));
people.Add(new Person(26, "Andrew"));
Session["mylist"] = people;
Response.Redirect("Default2.aspx");
}
===============
Default2.aspx.cs
===============
List<Person> people = new List<Person>();
public class Person
{
public int age;
public string name;
public Person(int age, string name)
{
this.age = age;
this.name = name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["mylist"] != null)
{
//casting problem line below
people = (List<Person>)Session["mylist"];
}
}
====================
I am having problems retrieving a List of objects
from a Session variable on page Default2.aspx.
A "casting" error is generated. Please see code
below. Could anybody help?
Thanks,
Jacques
===============
Default.aspx.cs
===============
List<Person> people = new List<Person>();
public class Person
{
public int age;
public string name;
public Person(int age, string name)
{
this.age = age;
this.name = name;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
people.Add(new Person(50, "Fred"));
people.Add(new Person(30, "John"));
people.Add(new Person(26, "Andrew"));
Session["mylist"] = people;
Response.Redirect("Default2.aspx");
}
===============
Default2.aspx.cs
===============
List<Person> people = new List<Person>();
public class Person
{
public int age;
public string name;
public Person(int age, string name)
{
this.age = age;
this.name = name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["mylist"] != null)
{
//casting problem line below
people = (List<Person>)Session["mylist"];
}
}
====================