question

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 asked YijingSun-MSFT answered

How to return a change to a dynamic textbox

I have two dynamically created text boxes, I'll call "txt1000" and "txt2000".
Here's what I can do so far:

  1. Type in a code in txt1000.

  2. Press <enter> and get to the method for event TextChanged.

  3. Use the code to get a description of the code.

How can I now do the following:
1. Send the description to txt2000.

Can that be done? I can use FindControl to focus on "txt2000", but I have no idea how to fill the text property of it!

dotnet-aspnet-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
1 Vote"
YijingSun-MSFT answered

Hi @CoreyFleig-6304 ,
If you directly find the id is "txt2000",you could pass the value from txt1000 to txt2000.Just like this:

  protected void Page_Load(object sender, EventArgs e)
         {
             for (int i = 1; i <=2; i++)
             {
                 AddControls(i);
             }
         }
         private void AddControls(int controlNumber)
         {
             var newPanel = new Panel();
             var newLabel = new Label();
             var newTextbox = new TextBox();
    
             // textbox needs a unique id to maintain state information
             newTextbox.ID = "TextBox_" + controlNumber;
    
             newLabel.Text = "txt"+controlNumber+"000: ";
    
             // add the label and textbox to the panel, then add the panel to the form
             newPanel.Controls.Add(newLabel);
             newPanel.Controls.Add(newTextbox);
             newTextbox.AutoPostBack = true;
             newTextbox.TextChanged += new System.EventHandler(this.txtBox_TextChanged);
             form1.Controls.Add(newPanel);
         }
         private void txtBox_TextChanged(object sender, EventArgs e)
         {
             var x= (sender as TextBox).Text;
             TextBox txt2 = (TextBox)form1.FindControl("TextBox_2");
             txt2.Text = x;
         }

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.