S
Steve Richter
a simple web page that adds controls to a Panel control at run time.
Problem is, on PostBack, all the controls I added to the Panel are
missing! ViewState is enabled on the panel. What happened to the
child controls of the Panel?
thanks,
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
{
BuildFormPanel(Panel1);
}
Response.Write( "<br> Panel.EnableViewState: " +
Panel1.EnableViewState.ToString( )) ;
Response.Write( "<br> Panel.HasControls: " +
Panel1.HasControls( ).ToString( )) ;
foreach (Control cntrl in Panel1.Controls)
{
Response.Write("<br> " + cntrl.ID);
}
}
void BuildFormPanel(Panel InPanel)
{
TextBox tb = null;
Label lbl = new Label();
InPanel.Controls.Add(lbl);
lbl.Text = "User Registration Form" ;
lbl.CssClass = "title";
InPanel.Controls.Add( new LiteralControl( "<br/>" )) ;
InPanel.Controls.Add(new LiteralControl("<br/>"));
}
</script>
<body>
<form id="form1" runat="server">
<div>
<aspanel ID="Panel1" CssClass="formPanel" runat="server">
</aspanel>
</div>
<asp:Button runat=server ID="Button3" Text="Run" />
</form>
</body>
</html>
Problem is, on PostBack, all the controls I added to the Panel are
missing! ViewState is enabled on the panel. What happened to the
child controls of the Panel?
thanks,
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
{
BuildFormPanel(Panel1);
}
Response.Write( "<br> Panel.EnableViewState: " +
Panel1.EnableViewState.ToString( )) ;
Response.Write( "<br> Panel.HasControls: " +
Panel1.HasControls( ).ToString( )) ;
foreach (Control cntrl in Panel1.Controls)
{
Response.Write("<br> " + cntrl.ID);
}
}
void BuildFormPanel(Panel InPanel)
{
TextBox tb = null;
Label lbl = new Label();
InPanel.Controls.Add(lbl);
lbl.Text = "User Registration Form" ;
lbl.CssClass = "title";
InPanel.Controls.Add( new LiteralControl( "<br/>" )) ;
InPanel.Controls.Add(new LiteralControl("<br/>"));
}
</script>
<body>
<form id="form1" runat="server">
<div>
<aspanel ID="Panel1" CssClass="formPanel" runat="server">
</aspanel>
</div>
<asp:Button runat=server ID="Button3" Text="Run" />
</form>
</body>
</html>