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

The Archive Base Latest Questions

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

My code generates an TextBox on the fly in C# ( page_load function). Can

  • 0

My code generates an TextBox on the fly in C# (page_load function). Can I access it in the code later? It does give me compilation error and does not seem to work. Can someone verify ?

Code for additonal problem

aContent += "<table>";
aContent += "<tr><td>lablel </td><td style='bla blah'><input type='textbox' id='col-1' name='col-1'/></td></tr> ... 10 such rows here
</table>"

spanMap.InnerHtml = aContent;

The contents are rendered OK but recusrive iteration does not return the textbox. I am calling it like this

 TextBox txt = (TextBox)this.FindControlRecursive(spanMap, "col-1");
 // txt = (TextBox) spanMapping.FindControl("col-1"); this does not work too
 if (txt != null)
 {
      txt.Text = "A";
 }
  • 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-26T21:35:52+00:00Added an answer on May 26, 2026 at 9:35 pm

    Assuming that you’re persisting it correctly, you should be able to access it in code-behind using the FindControl method. Depending on where the control is, you may have to search recursively through the control hierarchy:

    private Control FindControlRecursive(Control root, string id)  
    {  
        if (root.ID == id) 
        {  
            return root;  
        }  
    
        foreach (Control c in root.Controls)  
        {  
            Control t = FindControlRecursive(c, id);  
            if (t != null)  
            {  
                return t;  
            }  
        }  
    
        return null;  
    } 
    

    Using FindControlRecursive:

    TextBox txt = this.FindControlRecursive(Page.Form, "TextBox1") as TextBox;
    if (txt != null)
    {
        string text = txt.Text;
    }
    

    If you still can’t find it using the above method, make sure that you’re creating the control during after every postback, somwhere before Page_Load, like OnInit.

    EDIT

    I think you need to change the way you’re adding content to the container. Instead of using a <span>, I would use a Panel, and instead of building markup, simply add controls to the panel in code-behind:

    TextBox txt = new TextBox();
    txt.ID = String.Format("txt_{0}", Panel1.Controls.Count);
    Panel1.Controls.Add(txt);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following line of code generates the compile time error (PE19) There is no
I have the following code (generates a quadratic function given the a, b, and
With this code: function setupRow(event, ui) { var textbox, // how do i get
I have written a javascript to generate textbox dynamically. Code: function addtextbox(val) { var
Can someone give me a sample code to confine the cursor on to a
I am trying to get access to a named TextBox (textBoxAnswer) in the code
The following code generates the primaey key for the new record to be inserted
The following code generates warning C4250. My question is, what's the best solution to
The following code generates a FileNotFoundException (using .NET 2.0): using System; using System.Collections.Generic; using
I don't understand why the following code generates a warning. interface Generic<T> { }

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.