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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:39:38+00:00 2026-06-18T22:39:38+00:00

I am generating the text boxes dynamically.Table rows are created dynamically too, and these

  • 0

I am generating the text boxes dynamically.Table rows are created dynamically too, and these text boxes are added to those dynamically created row cells and they are added to the table using the following code

protected override void OnInit(EventArgs e)
{
    PopulateTextBoxes();
    SetFocus();
    base.OnInit(e);
}
protected void PopulateTextBoxes()
{
    int quantityRequired = 0;
    quantityRequired =GetQuantity();
    for (int j = 0; j < quantityRequired; j++)
    {
        TableRow row = new TableRow();
        TableCell cell1 = new TableCell();
        TextBox tb = new TextBox();
        tb.ID = j.ToString() +"_RowTbx"
        tb.AutoPostBack = true;
        tb.TextChanged += new EventHandler(tb_TextChanged);
        cell1.Controls.Add(tb);
        row.Cells.Add(cell1);
        TableCell cell2 = new TableCell();
        CheckBox chBox = new CheckBox();
        chBox.CheckedChanged += new EventHandler(chBox_CheckedChanged);
        chBox.AutoPostBack = true;
        cell2.Controls.Add(chBox);
        row.Cells.Add(cell2);
        TableCell cell3 = new TableCell();
        Image img = new Image();
        img.Width = Unit.Pixel(25);
        img.Height = Unit.Pixel(25);
        img.ImageUrl = "HttpRuntime.AppDomainAppVirtualPath" + "/Images/" +"img.jpeg";
        cell3.Controls.Add(img);
        row.Cells.Add(cell3);
        tbl_Serial.Rows.Add(row);
    }
    LoadDataIfExists();
}

private void tb_TextChanged(object sender, EventArgs e)
{
  //I have implemented code to validate the text entered in the text box.
}

protected void SetFocus()
{
    int emptytbxRow = 0;
    TextBox tbx = new TextBox();
    for (int i = 0; i < tbl_Serial.Rows.Count; i++)
    {
        string tbxId = i.ToString() + "_RowTbx";
        string text = ((TextBox)tbl_Serial.Rows[i].Cells[0].FindControl(tbxId))).Text;
        if (text == null || text==string.Empty)
        {
            tbx=((TextBox)(tbl_Serial.Rows[i].Cells[0].FindControl(tbxId)));
            if (tbx != null)
                tbx.Focus();
        }
    }
  protected void LoadDataIfExists()
  {
     List<string> lstData=Service.GetData(int someNum)
     for (int j = 0; j < lstData.Count; j++)
        {
            string tbxID = j.ToString() + "_RowTbx";
            TextBox tbx = (TextBox)tbl_Serial.Rows[j].Cells[0].FindControl(tbxID);
            tbx.Text = lstData[j];

        }

   }

When I debug, the tbx.focus seems to hit rightly but i do not see the cursor blinking on the text box in my UI.I do not know if I am missing something imp. Thank you.

Edit: Sorry I was not clear. When the page loads, the text boxes may contain data, but not all text boxes contain data. So whenever the page loads there are a few text boxes with data and there are empty ones. I want the cursor to be at the first empty box.

  • 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-18T22:39:39+00:00Added an answer on June 18, 2026 at 10:39 pm

    For some unknown reason , C#code with the same logic as below did not work, while javascript works. Hope the following helps someone in future. Thank you Liqua for providing the start.

            window.onload = function () {
                                          FindWhichTextBoxIsEmpty();
                                        }
        function FindWhichTextBoxIsEmpty() {
            var tableSerial = document.getElementById('tbl_Serial');
    
            for (var i = 0; i < tableSerial.rows.length-1; i++) {
    
                var ID = i.toString() + "_RowTbx";
                if (document.getElementById(ID).value!="") {
                    var tb = document.getElementById(ID).value;
                    if (tb != "") {
                                  if (i + 1 < tableSerial.rows.length-1) {
                                 var nextID = (i + 1).toString() + "_RowTbx";
                                 document.getElementById(nextID).focus();
                        }
                    }
                }
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got ASP generating the embed code on my page as follows: Table1.Rows(0).Cells(0).Text =
I have a page that is currently generating dynamically created textboxes in a table
Hi am generating input boxes dynamically base on database keys. <input type=text id=101 name=101>
I'm generating an image out of text using php. My code works perfectly on
I am generating a .png image that contains a text dynamically written. I need
I am generating an XML document from a StringBuilder, basically something like: string.Format(<text><row>{0}</row><col>{1}</col><textHeight>{2}</textHeight><textWidth>{3}</textWidth><data>{4}</data><rotation>{5}</rotation></text> Later,
Playing around with generating text randomly with each page refresh using php. Is there
My C# code is generating several text files based on input and saving those
I am dynamically creating a table with data and check boxes in it, my
What I tried to do is generating a text file on ASP.Net using C#.

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.