How to add a dynamic text box in ASP.NET?

I have the following requirement for my asp.net page:

  • The user can add a dynamic text box on page A by clicking the "Add a new category" hyperlink

  • He presses the submit button on page A and redirects to page B.

  • When he clicks the link on the Link page on this page, the text fields that he added should be saved.

Can someone help me with the code on this?

Appreciate your help!

+3
source share
5 answers

In the ButtonClick method write.

TextBox tb = new TextBox();

Parent.Controls.Add( tb );

A parent is a control to which you want to add a text field, such as a panel.

.

, .

+3

. , , , " ", .

, .

+3

:

, , enter image description here

"1" "", .. , enter image description here

. ""... btnadd_click,

protected void btnadd_Click ( , EventArgs e)  {

    int i;
       for (i = 0; i < Convert.ToInt32(txtno.Text); i++)

    {

        TextBox txtbox = new TextBox();
        phtxt.Controls.Add(txtbox);

        phtxt.Controls.Add(new LiteralControl("<br>"));

    }

  }

... , enter image description here

+1

, , , , . , . , , -. , , , , .

. Onload, , . viewstate. viewstate, . .

0

.

as a rule, I follow when you create a dynamic user control, then you must set its identifier so that ASP.net can redistribute it on the back side and save the values ​​of the controls after sending back, you must reload the user controls the Page_Init event.

hope this helps.

0
source

Source: https://habr.com/ru/post/1706236/


All Articles