ASP.NET 2.0 Beta 2 - Session no longer stores UserControls? -
08-22-2005
, 08:34 AM
Hi,
I am having a problem in storing/retrieving a user control from session.
Although this code works in ASP.NET Beta 1, in Beta 2 I cannot seem to make
it work.
Here is the thing….
I have the following class:
public class test : UserControl
{
private Button b;
public test()
{
b = new Button();
b.Text = “Something”;
this.Controls.Add(b);
}
}
Now, I create an empty aspx page with the following C# Code attached to it:
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// I create a new object my of UserControl
test t = new test();
if(!IsPostBack)
{
Session[“X”] = t;
this.form1.Controls.Add(t);
//Works fine. The first time the page is loaded, the button is displayed
//and it is stored in the session as well.
}
else
{
//the second time around, although the class is stored in the session
//the control is not added in the web form!
t = (test)Session[“X”];
this.form1.Controls.Add(t);
}
}
}
Any ideas why this is happening? |