HighTechTalks DotNet Forums  

ASP.NET 2.0 Beta 2 - Session no longer stores UserControls?

Dotnet Scripting microsoft.public.dotnet.scripting


Discuss ASP.NET 2.0 Beta 2 - Session no longer stores UserControls? in the Dotnet Scripting forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Panos
 
Posts: n/a

Default 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?

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.