0
votes

I have created several labels,textboxes, and buttons from an array. Now, I am not sure how to program those objects. For example, I want to program a button that will enable a text-box (from the array), capture variables, manipulate the variables, etc just like any other object that is in the form. Furthermore, I am working on ASP.net with C#.net back-end code. how do I double click on the object to generate the following block of code "private void btnDisplay_Click(object sender, EventArgs e)" and how do I make reference to a textbox as well to capture the input information?

The following code is within a button that is actually in the form and generates labels, textbox, and buttons.

  Button [] buttons = new Button[2];

       for (int i = 0; i < buttons.Length ; i++)
        {
            buttons[i] = new Button();
            buttons[i].ID = "BTN0" + i;
            if (i == 0)
            {
                buttons[i].Text = "Send Web API Request";
            }
            if (i == 1)
            {
                buttons[i].Text = "Manually Input Information";
            }
        }

        for (int i = 0; i < buttons.Length ; i++)
        {
            pnlButton.Controls.Add(buttons[i]);
            Literal lit = new Literal();
            lit.Text = "</br></br>";
            pnlButton.Controls.Add(lit);
        }

        TextBox[] textBoxes = new TextBox[n];
        Label[] labels = new Label[n];


        for (int i = 0; i < n; i++)
        {
            labels[i] = new Label();
            labels[i].ID = "LBL0" + i;
            labels[i].Text = lines3[i];
            textBoxes[i] = new TextBox();
            textBoxes[i].ID = "TXT0" + i;

        }

  for (int i = 0; i < n; i++)
        {

            pnlQuestionsLBLS.Controls.Add(labels[i]);
            Literal lit = new Literal();
            lit.Text = "</br></br>";
            pnlQuestionsLBLS.Controls.Add(lit);


            pnlQuestionsTXTS.Controls.Add(textBoxes[i]);
            Literal lit2 = new Literal();
            lit2.Text = "</br></br>";
            pnlQuestionsTXTS.Controls.Add(lit2);


        }
    }
1
It looks like you are trying to program in ASP.NET the same way you did in WinForms. I'd recommend doing a tutorial or two about WebForms, since even though it was designed to be an easy transition for WinForms devs, it is essentially very different due to the nature of web development in general. Those tutorials may give you a better understanding of that, as well as answering most of the questions in this postAndrei

1 Answers

0
votes

Add your clickfunction:

buttons[i].Click += new EventHandler(this.btnDisplay_Click);

Captures the input in a string and disables your textbox:

    void btnDisplay_Click(Object sender, EventArgs e)
    {

        string textboxInput = textBoxes[i].text;
        textBoxes[i].enabled = false;

    }