c# - Get dynamically created asp control ids(values) using for loop -


how can access similar asp control id's using for loop? have following asp text boxes.

<asp:textbox id="pftxtname1" runat="server"></asp:textbox> <asp:textbox id="pftxtname2" runat="server"></asp:textbox> <asp:textbox id="pftxtname3" runat="server"></asp:textbox> <asp:textbox id="pftxtname4" runat="server"></asp:textbox> <asp:textbox id="pftxtname5" runat="server"></asp:textbox> <asp:textbox id="pftxtname6" runat="server"></asp:textbox> 

and want access these text box value through loop using jquery, how can do?

i tried value below code, shows error.

var ar_val=[]; for(i=0;i<7;i++) {   var txtv = $("#<%=pftxtname"+i+".clientid%>").val().trim();   ar_val.push(txtv); } 

you mixing client side , server side code, not work way.

add commom css class textboxes :

<asp:textbox id="pftxtname1" runat="server" cssclass="txtname"></asp:textbox> 

and iterate on elements in jquery using class selector:

$(".txtname").each(function() {      alert($(this).val()) // value     alert(this.id)   // id  }) 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -