Click here to Skip to main content
15,994,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I use a repeator control.
Inside that a textbox is placed, then I put a jQuery for validate that textbox.

When more than one textbox is generated inside the repeator control, this jQuery is not working (jQuery validator is working for the first textbox...).

When more than one textbox is generated the validation is not working.

Here is my jQuery.
Please refer that.

XML
<script type="text/javascript">
         var retValue = false;

         function ValidateBlock() {
             var txtBlockName = $("input[attr-identity=txtBlockName]").val();

           //  txtBlockName = replaceSpace(txtBlockName);

             if (txtBlockName == "") {

                alert("Please Enter Block Name");
                 $("input[attr-identity=txtBlockName ]").val('');
                 $("input[attr-identity=txtBlockName ]").focus();

                 return false;
             }
             else {

                 return true;
             }
         }
</script>


In text box...
--------------
XML
<asp:Repeater ID="RepBlockEntry" runat="server" OnItemDataBound="RepBlockEntry_ItemDataBound">
                                                   <ItemTemplate>

XML
<asp:TextBox ID="txtBlockName" MaxLength="15" runat="server" Text='<%#Eval("BlockName") %>'
                                                                  OnTextChanged="txtBlockName_TextChanged" AutoPostBack="false" attr-identity="txtBlockName"></asp:TextBox>

XML
</ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>

On button ...
---------------------
XML
<asp:Button ID="btnSaveBlock" runat="server" Text="Save" Visible="false" CssClass="addbutton" ValidationGroup="BlockEntry" OnClick="btnSubmitBlock_Click" OnClientClick="return ValidateBlock();" />
Posted
v2

i guess you have to use $.each() function to loop through each text box in repeater.
 
Share this answer
 
Comments
aravindnass 16-Mar-13 6:59am    
I am new in jquery..So How can I use $.each().
if your HTML is:
<div>
 <ul>
   <li>foo</li>
   <li>bar</li>
 </ul>
</div>


then you can use like
$( "div ul li" ).each(function() {
alert($(this).val();)
});

to loop through each li element.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900