Home > DeveloperSection > Forums > how to get values from dynamically generated text boxes?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    September-29-2014 12:53 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 657  View(s)
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



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-29-2014 1:05 AM

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

 

});


Don't want to miss updates? Please click the below button!

Follow MindStick