input
input

Reputation: 7519

validating dynamic controls using jquery

how do i validate dynamic textboxes which are generated at runtime using jQuery?

Upvotes: 0

Views: 1510

Answers (2)

Chad Grant
Chad Grant

Reputation: 45382

<%    
        TextBox tb = new TextBox();
        tb.Attributes.Add("data-validateme","true");
        Page.Controls.Add(tb);
%>

Which will add an HTML5 data attribute.

<input type="text" data-validateme="true" />

jQuery:

$(document).ready(function(){
   $("*[data-validateme]").change(function(){
      alert($(this).val());
   });
});

Upvotes: 1

Amr Elgarhy
Amr Elgarhy

Reputation: 68922

I am not sure, but you can use something like this:

$(function() {
$('input').each(function() {
    $('#' + this.id).live('onchange', function() {  
        // VALIDATION Code
    });
});

Upvotes: 0

Related Questions