tags:

views:

16

answers:

1

Good Day,

I'm using an ASP.NET Repeater control to create rows of textboxes. I'm able to capture the value of the textboxes, but I would like to validate that all the textboxes have a value inside.

Is this possible to do in jQuery?

TIA,

coson

+1  A: 

Sure it is.

$(".submit-button").click(function() {
    $("class-or-id-of-repeater").find("input[type=text]").each(function() {
        if($.trim($(this).val()) == '') {
            alert("At least one textbox is empty");
            $(this).focus(); // focus the element
        }
    })
});

If you create Dynamic Controls in ASP.NET, the textboxes will still be rendered on the page after the postback.

I haven't tested this using an UpdatePanel, it might break if you used one.

Marko
Your code didn't initially work for me because the Repeater tag isn't generated as part of the markup when rendered in the browser, so I wrapped the Repeater control into a DIV. Then your code worked!! Thanks alot!!
coson
@coson - excellent, click the tick next to my answer :)
Marko