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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:57+00:00 2026-06-04T16:15:57+00:00

I change my question because it probably was not understood. Also sorry for my

  • 0

I change my question because it probably was not understood. Also sorry for my English…

Dynamically create TextBoxes which put them in array.

A piece of my code:

public partial class NewArticleForm : System.Web.UI.Page
{
    private Label[] lblName;
    private TextBox[] txtName;
    private Label[] lblSurname;
    private TextBox[] txtSurname;
    private PlaceHolder PlaceHolder1;

    public int NumberOfOtherAuthors()
    {
        Int32 index = Convert.ToInt32(NumberList.SelectedValue);
        return index;
    }

    public void dataofOtherAuthor()
    {
        int authors;
        int i = 0;
        int j=1
        authors = NumberOfOtherAuthors();
        lblName = new Label[authors];
        txtName = new TextBox[authors];
        lblSurname = new Label[authors];
        txtSurname = new TextBox[authors];
        PlaceHolder1 = new PlaceHolder();
        for (i = 0; i < authors; i++)
        {
            Label authorInformation = new Label();
            authorInformation.Text = "Information for Author " + j.ToString() + " :";
            lblName[i] = new Label();
            lblName[i].Text = "Name:";
            txtName[i] = new TextBox();
            lblSurname[i] = new Label();
            lblSurname[i].Text = "Surname:";
            txtSurname[i] = new TextBox();    
            PlaceHolder1.Controls.Add(authorInformation);
            PlaceHolder1.Controls.Add(lblName[i]);
            PlaceHolder1.Controls.Add(txtName[i]); 
            PlaceHolder1.Controls.Add(lblSurname[i]);
            PlaceHolder1.Controls.Add(txtSurname[i]);    
            // Add a spacer in the form of an HTML <BR> element.
            Panel1.Controls.Add(PlaceHolder1);
            j++;      }  }

 protected void NumberList_SelectedIndexChanged(object sender, EventArgs e)
    {
        dataofOtherAuthor();
    }

    private void UploadForm()
    {
        int numberOfOtherAuthors = NumberOfOtherAuthors();
        int i=0;

            for (i = 0; i < numberOfOtherAuthors; i++)
            { 
                Label1.Text = txtName[i].Text;       

            }
        }


    protected void btnUpload_Click(object sender, EventArgs e)
    {
            UploadForm();
    }
}

How can I get the value of textboxes??
Specifically I want to pass the data in a database. Label is a test if I get the value.

Thank you!!!

  • 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-04T16:15:58+00:00Added an answer on June 4, 2026 at 4:15 pm

    Not sure if you are aware or not, but you are placing PlaceHolder1 in Panel1 in every iteration of your for loop. Maybe you meant to do Panel1.Controls.Add(PlaceHolder1); after the for loop?
    Anyway, you have placed these TextBox controls into the form. If you are trying to access them via postback, you need to either access them by their set ID, or access them through their asp containers (while setting runat="server"):

    x = (p1.Controls[placeHolderIndex].Controls[textBoxIndex] as TextBox).Text;
    

    or you could try

    x = (p1.FindControl("placeHolder_ID").FindControl("textBox_ID") as TextBox).Text;
    

    again make sure they are all runat="server"

    txtName will not retain its value after a postback.

    Have your second loop do something more useful than overwrite the set string as well; maybe add each value to a List

    List<string> x = new List<string>();
    for (i = 0; i < authors; i++)
    {  
       x.Add((p1.Controls[placeHolderIndex].Controls[i] as TextBox).Text);
       //increment placeHolderIndex if you don't change your design
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please forgive the newb question, but I am not finding answers elsewhere... probably because
I think the title for this question is probably wrong, but I'm not sure
Sorry for probably simple question but I'm a newby in Django and really confused.
I'll rewrite a different question of mine, because the problem case somewhat changed: If
I want to change my question. please let me know what's happening; type is
I found the following regex from another Stack Overflow question: Change an element's class
With the reference to this question:- JavaScript -Change CSS color for 5 seconds Working
a simple question here Is there a way to change the text click here
Second question of the day but hopefully simple, I just need to change the
I have a very simple question: Is it possible to change the price of

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.