what happened to the controls of my Panel control?

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>
<asp:panel ID="Panel1" CssClass="formPanel" runat="server">

</asp:panel>
</div>

<asp:Button runat=server ID="Button3" Text="Run" />

</form>
</body>
</html>
 
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?

never mind, I got it. I had forgotten that when I add the controls
back on each Page_Init ASP.NET magically applies the posted values of
those controls. Kind of confusing. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top