J
Joachim
Hello,
I have a problem with dynamical creation of controls on a WebPage. The
program works with the VS 2003 envrionment but not with the VS 2005
8.0.50215.44. To demonstrate it, I have make a simple demonstation
program that adds a Panel with two Label to the HtmlForm element.
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Control f = FindControl(this.Controls, typeof(HtmlForm));
if (!this.IsPostBack)
{
Panel p = new Panel();
Label l = new Label();
l.Text = "Label 1";
p.Controls.Add(l);
l = new Label();
l.Text = " Label 2";
p.Controls.Add(l);
Session["panel"] = p;
f.Controls.Add(p);
}
else
{
Panel p = Session["panel"] as Panel;
f.Controls.Add(p);
}
}
The FindControl function (not show in the sample code) looks in the
controls collection for a control from the spezified type. On the form
I have a additional Button to make the postback.
On VS 2003 all works -> I see the two labels on the page when I click
the Button. With 2005 (convert the solution) I see the labels only the
first time.
When I debug the application, I see that the ControlsCollection of the
panel is empty when I read the panel from the session state. Under 2003
I have the two labels in the panel -> The full control collection is
save in the session state.
What must I do to have the functionality in VS 2005.
Joachim
I have a problem with dynamical creation of controls on a WebPage. The
program works with the VS 2003 envrionment but not with the VS 2005
8.0.50215.44. To demonstrate it, I have make a simple demonstation
program that adds a Panel with two Label to the HtmlForm element.
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Control f = FindControl(this.Controls, typeof(HtmlForm));
if (!this.IsPostBack)
{
Panel p = new Panel();
Label l = new Label();
l.Text = "Label 1";
p.Controls.Add(l);
l = new Label();
l.Text = " Label 2";
p.Controls.Add(l);
Session["panel"] = p;
f.Controls.Add(p);
}
else
{
Panel p = Session["panel"] as Panel;
f.Controls.Add(p);
}
}
The FindControl function (not show in the sample code) looks in the
controls collection for a control from the spezified type. On the form
I have a additional Button to make the postback.
On VS 2003 all works -> I see the two labels on the page when I click
the Button. With 2005 (convert the solution) I see the labels only the
first time.
When I debug the application, I see that the ControlsCollection of the
panel is empty when I read the panel from the session state. Under 2003
I have the two labels in the panel -> The full control collection is
save in the session state.
What must I do to have the functionality in VS 2005.
Joachim