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 6655155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:28:52+00:00 2026-05-26T01:28:52+00:00

I have textbox tb1 on my page and I want users to be able

  • 0

I have textbox “tb1” on my page and I want users to be able to add another if they need to input more data. I have the following code:

VB:

ViewState("num") = 2            
Dim MyTextBox = New TextBox
MyTextBox.ID = "tb" & ViewState("num")
MyTextBox.Width = 540
MyTextBox.Height = 60
MyTextBox.TextMode = TextBoxMode.MultiLine
AddScript.Controls.Add(MyTextBox)
AddScript.Controls.Add(New LiteralControl("<br>"))
ViewState("num") = ViewState("num") + 1

ASP:

<asp:PlaceHolder id="AddScript" runat="server">
    <asp:Label ID="Label2" runat="server" Font-Bold="true" 
        Text="Scripts: (Drag from right)"></asp:Label><br />
    <asp:TextBox ID="tb1" runat="server" Width="90%" Height="60px" 
        TextMode="MultiLine" Enabled="false"></asp:TextBox>
</asp:PlaceHolder>

My problem is that I can only add one text box each time and I also have a search button for the right panel on the page and if this button is clicked the created textbox will disappear. Any help would be appreciated.

  • 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-26T01:28:52+00:00Added an answer on May 26, 2026 at 1:28 am

    You could build your own TextBoxCollection CompositeControl which would enable you to achieve the functionality you require.

    I have put together a basic example of how it could be achieved.

    Control

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace ASPNetWebApplication.Controls
    {
        public class TextBoxCollection : CompositeControl
        {
            private List<string> TextBoxes
            {
                get
                {
                    if (ViewState["TextBoxes"] == null)
                    {
                        ViewState["TextBoxes"] = new List<string>();
                    }
    
                    return (List<string>)ViewState["TextBoxes"];
                }
                set
                {
                    ViewState["TextBoxes"] = value;
                }
            }
    
            protected override void CreateChildControls()
            {
                foreach (string textBox in TextBoxes)
                {
                    Controls.Add(new TextBox() { ID = textBox });
                    Controls.Add(new Literal() { Text = "<br/>" });
                }
            }
    
            public TextBox GetTextBox(string id)
            {
                return (TextBox)Controls.Cast<Control>().Where(t => (t.ID == null ? "" : t.ID.ToLower()) == id.ToLower()).SingleOrDefault();
            }
    
            public void AddTextBox(string id)
            {
                TextBoxes.Add(id);
            }
        }
    }
    

    Example Markup

    Note: Change Assembly="ASPNetWebApplication" to the name of your assembly.

    <%@ Register Assembly="ASPNetWebApplication" Namespace="ASPNetWebApplication.Controls" TagPrefix="ASPNetWebApplication" %>
    
    ...
    
    <ASPNetWebApplication:TextBoxCollection ID="TextBoxCollection1" runat="server" />
    <br />
    <asp:Button ID="AddTextBoxesButton" runat="server" OnClick="AddTextBoxesButton_Click" Text="Add Some Text Boxes" />
    <asp:Button ID="GetTextBoxValuesButton" runat="server" OnClick="GetTextBoxValuesButton_Click" Text="Get TextBox Values" Visible="false" />
    <br />
    <asp:Literal ID="TextBoxEntriesLabel" runat="server"></asp:Literal>
    

    Example Codebehind

    protected void AddTextBoxesButton_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            TextBoxCollection1.AddTextBox(string.Format("TextBox{0}", i));
        }
    
        AddTextBoxesButton.Visible = false;
        GetTextBoxValuesButton.Visible = true;
    }
    
    protected void GetTextBoxValuesButton_Click(object sender, EventArgs e)
    {
        TextBoxEntriesLabel.Text = string.Empty;
        for (int i = 0; i < 10; i++)
        {
            string textBoxId = string.Format("TextBox{0}", i);
            TextBoxEntriesLabel.Text += string.Format("TextBox: {0}, Value: {1}<br/>", textBoxId, TextBoxCollection1.GetTextBox(textBoxId).Text);
        }
    }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add
I have a textbox in a form that I created. I want to add
I have a TextBox named tb1 (Not real name). I want to, when I
I have asp.net page (Form = runat server ) 2 textboxes: <input type=text id=tb1
I have TextBox on my page. I want to validating this textbox. The rules
Im creating forum like application and I have textbox where users can enter tags
I have a textbox with ID name, I want to do validation when the
I have a textbox with id=Email in my view and I need the id
I have textbox textbox1 and I want to change text color, but in the
We have textbox on our MVC view. Once we load data, we are unable

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.