I would like to select a textbox being dynamically created by an asp.net server control (listview) For each row in the table I need to run some javascript functionality over it.
Below I am trying to select the textbox based off of the name haveing the text. Is there a "better" way of doing this?
$('#tblNewAttendees tr').each(function() {
var test = $(this).find('input[name$="txtFirstName"]').val();
});
}
Html code
<table>
<thead>
</thead>
<tbody>
<tr>
<td>
<asp:TextBox ID="txtFirstName" Text='<%#Eval("FirstName")%>'
runat="server" Width="80px" />
</td>
</tr>
</tobdy>
</table>
Assign a specific CSS class to all those text boxes, and then use class selectors to select those.
Suppose you have assigned myClass as CSS class value. Then use the following to select them -
$('#tblNewAttendees tr').each(function()
{
var test = $(this).find('input.myClass').val();
});
The reason is, as far as I remember, the names that you assign to a text box is replaced by ASP.NET with something new after it parses the document. Suppose you have a text box whose name is myBox. Then after the page is parsed, its name may become something like ct_1001_myBox_123 or something. So it's better to use a CSS class to select them in the client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With