what happened to the controls of my Panel control?

Discussion in 'ASP .Net' started by Steve Richter, May 29, 2007.

  1. 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>
     
    Steve Richter, May 29, 2007
    #1
    1. Advertising

  2. On May 29, 1:10 am, Steve Richter <> wrote:
    > 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. ;)
     
    Steve Richter, May 29, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry
    Replies:
    3
    Views:
    553
    Harry Singh
    Nov 10, 2003
  2. HS1
    Replies:
    3
    Views:
    490
  3. HS1
    Replies:
    4
    Views:
    8,304
    Babu Kalakrishnan
    Dec 8, 2004
  4. Ulf Meinhardt
    Replies:
    0
    Views:
    619
    Ulf Meinhardt
    Jul 7, 2009
  5. Robin Wenger
    Replies:
    0
    Views:
    2,940
    Robin Wenger
    Aug 18, 2011
Loading...

Share This Page