how to get values from dynamically generated text boxes?

Total Post:154

Points:1086
 1206  View(s)
Ratings:
Rate this:

I am trying to get the values of text box which i generated dynamically on page load and cloned them using jquery....

 

every text box has a unique id in form of a matrix for eg textboxes of row one have ids textbox11,textbox12,textbox13,textbox14 etc for row two textbox21,textbox22,textbox23........ 

is there any way to get the values.. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class product_entry : System.Web.UI.Page
{
    int count;
    protected void Page_Load(object sender, EventArgs e)
    {
        int i, j;
        for (i = 0; i < 1; i++)
        {
            TableRow tr = new TableRow();
            tr.Attributes.Add("class", "tabrow");
 
            for (j = 0; j <= 8; j++)
            {
                TableCell tc = new TableCell();
 
                if (j == 0)
                {
                    tc.Controls.Add(new LiteralControl("<Button class=remove type=button>-</button>"));
                }
                if (j == 1)
                {
                    tc.Attributes.Add("class", "sno");
                }
                if (j == 2 || j == 3 || j == 4 || j == 5 || j == 6 || j == 7 || j == 8)
                {
                    TextBox tb = new TextBox();
                    tb.Style["width"] = "98%";
                    tc.Controls.Add(tb);
                }
                tr.Controls.Add(tc);
            }
            Table1.Controls.Add(tr);
        }
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label2.Text = TextBox1.Text;
    for (int i = 1; i <= count; i++)
    {
        for (int j = 1; j <= 7; j++)
        {
            TextBox aa = (TextBox)Pnl.FindControl("textbox" + i + j);
            Response.Write(aa.Text);
        }
    }
    }
}

i want to fetch the values of hundreds of text boxes geerated using jquery by using the loop designed above is there any way to do that

  1. Post:378

    Points:2694
    Re: how to get values from dynamically generated text boxes?

    Hi Manoj, 


    you can add a specific css class to all dynamically generated text boxes on page load and by class selector using Jquery you can access all of them: 

    Use each: i is the postion in the array, obj is the DOM object that you are iterating (can be accessed with the jQuery wrapper $(this) as well). 

    $('input.SomeClass').each(function(i,obj){
     
    var textboxid = $(this).id;
    var textboxValue = $(this).val(); // get text inside text box
     
    });

      Modified On Apr-05-2018 06:15:27 AM

Answer