Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:26:28+00:00 2026-06-15T05:26:28+00:00

I have a form which, based on the answers given in the prior page,

  • 0

I have a form which, based on the answers given in the prior page, can have about 10 different variations in the combination of fields (most are the same, but several change). I decided rather than making 10 separate pages, I would try to make it dynamic. Eventually this will pull the form setup from a database, but for now I’m just trying to get the dynamic part to work. The following code kinda works, but it’s giving me a weird result.

private void AddTestControls()
{
    var newbox = new TextBox();
    newbox.ID = "FirstBox";
    newbox.Text = "This is dynamic";
    newbox.CssClass = "stepHeader";
    DynamicDiv1.Controls.Add(newbox);

    var newlit = new Literal();
    newlit.ID = "FirstLit";
    newlit.Text = ".<br/>.";
    DynamicDiv1.Controls.Add(newlit);

    newbox.ID = "SecondBox";
    newbox.Text = "This is also dynamic";
    newbox.CssClass = "step";
    DynamicDiv1.Controls.Add(newbox);

}

I’ve stepped through it and all the properties are getting set correctly, but when the page finally renders, only the SecondBox control is visible. There is no trace of the FirstBox. If I change it so that SecondBox is its own object (newebox2 for example) then both are visible, but with how I was thinking that I would ultimately do the form from the database, this could complicate things. I don’t understand why the textbox object has to be recreated in order to add it to the Div’s collection of controls. Am I going about this all wrong, or just missing a step somewhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:26:29+00:00Added an answer on June 15, 2026 at 5:26 am

    Your “SecondBox” are overwriting the “FirstBox” newbox since it’s still holding a reference to it. Create a new TextBox for the second box:

    var newbox = new TextBox();
    newbox.ID = "FirstBox";
    newbox.Text = "This is dynamic";
    newbox.CssClass = "stepHeader";
    DynamicDiv1.Controls.Add(newbox);
    
    var newlit = new Literal();
    newlit.ID = "FirstLit";
    newlit.Text = ".<br/>.";
    DynamicDiv1.Controls.Add(newlit);
    
    // Create a new TextBox
    var secondBox = new TextBox();
    secondBox.ID = "SecondBox";
    secondBox.Text = "This is also dynamic";
    secondBox.CssClass = "step";
    DynamicDiv1.Controls.Add(secondBox);
    

    I’m not quite sure why this could complicate things, but what you could do is create a method for creating a textbox, if that’s easier:

    TextBox CreateTextBox(string id, string text, string cssClass)
    {
        var box = new TextBox();
        box.ID = id;
        box.Text = text;
        box.CssClass = cssClass;
        return box;
    }
    

    And then

    var newBox = CreateTextBox("FirstBox", "This is dynamic", "stepHeader");
    DynamicDiv1.Controls.Add(newBox);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 20 text fields on a form that a user can fill
I have a form which has elements in a couple of divs. Based on
I have made a Base Form which is inherited by most Forms in the
I have a form which has three inputs when the page loads -- 2
I have an HTML form with plenty of inputs, most of which are optional.
I have a form which is dynamically generated based on user input. Initially the
I have a base and derived class called Node which form elements of a
I have a form which I want to be 'resusable' for a variety of
I have a form which has a RichTextBox docked to the left and DataGridView
I have a form which POST's its data via AJAX: $.ajax({ type: POST, url:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.