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

  • Home
  • SEARCH
  • 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 3985352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:52:49+00:00 2026-05-20T05:52:49+00:00

I have a problem which is bothering me for three days. On my web

  • 0

I have a problem which is bothering me for three days.

On my web form I want to have a button, on which click I want to make dynamicly five text boxes in asp:PlaceHolder.

And I want, that values which I enter in this texBoxes, are saved even after postBack. With second button i want to store them.

I’ve read articles about lifecycle of page, viewState, IsPostBack,… a lot of articles of dynamically created controls, but I’m still not able to program this.

There are several ways I tried, but without success. Below is the last version of my “masterpiece”. Please help me to crate this task, because it makes me sick. Thanks, Martin

namespace DynamicCreate
{
    public partial class _Default : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox textBox;

        private TextBox[] my_dynamicTextBoxes = new TextBox[5];
        private string[] textBoxValues = new string[5];

        protected void Page_Load(object sender, System.EventArgs e)
        {
            btn_save_tb_values.Click += new EventHandler(save_btnClick);
            but_load_tb.Click += new EventHandler(creat_tb_btnClick);

            int i = 0;
            foreach (TextBox tb in my_dynamicTextBoxes)
            {
                if (ViewState["c_textBox" + i.ToString()] != null)
                {
                    tb.Text = (string)ViewState["c_textBox" + i.ToString()];
                    i++;
                }
                else
                {
                    textBox = new TextBox();
                    textBox.ID = "c_textBox" + i.ToString();
                    my_dynamicTextBoxes[i] = textBox;
                    i++;
                }
            }
        }

        protected void creat_tb_btnClick(object sender, EventArgs e)
        {
            int i = 0;
            foreach (TextBox neww in my_dynamicTextBoxes)
            {
                c_placeholder.Controls.Add(neww);
                c_placeholder.Controls.Add(new LiteralControl("<br>"));
                ViewState["c_textBox" + i.ToString()] = neww.Text;
                i++;
            }
        }

        protected void save_btnClick(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++) {}
        }
    }
}



<form id="form1" runat="server">
        <div>
            <div>  <asp:PlaceHolder ID="c_placeholder" runat="server"></asp:PlaceHolder>    </div>
            <div>   <asp:Button runat="server" ID="but_load_tb"  Text="Dodaj Polja!!"/>       </div>
            <div>   <asp:Button runat="server" ID="btn_save_tb_values" Text="Izpisi Vrednosti!" />   </div
        </div>
    </form>
  • 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-05-20T05:52:50+00:00Added an answer on May 20, 2026 at 5:52 am

    Here’s a simple example I came up with that will dynamically add 5 textboxes to a PlaceHolder when you click a “Create” button and will bring up the values when you click a “Save” button:

    Default.aspx:

    <asp:PlaceHolder ID="phButtons" runat="server" />
    <asp:Button ID="btnCreate" Text="Create" runat="server" onclick="btnCreate_Click" />
    <asp:Button ID="btnSave" Text="Save" runat="server" onclick="btnSave_Click" />
    

    Default.aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState["buttons"] != null)
            CreateButtons();
    }
    
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        ViewState["buttons"] = true;
        CreateButtons();
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (ViewState["buttons"] != null)
        {
            // Save the button information.
            foreach (Control ctl in phButtons.Controls)
            {
                string x;
                if (ctl is TextBox)
                    x = (ctl as TextBox).Text;
            }
        }
    }
    
    private void CreateButtons()
    {
        for (int iLoop = 0; iLoop < 5; iLoop++)
        {
            phButtons.Controls.Add(new TextBox() { ID = "txt" + iLoop });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a little .Net web application which uses the Amazon
this is my first post. I have a huge problem which make me headaches.
I have a problem which requires me to parse several log files from a
I have a problem which I think is related to forward declarations, but perhaps
I have a very simple problem which requires a very quick and simple solution
I have a problem with a string in C++ which has several words in
I have a problem with an application which uses the same stored procedure over
I have a problem in my project with the .designer which as everyone know
I have a problem, which I do not seem to be able to solve...
The problem: I have a class which contains a template method execute which calls

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.