Thursday, May 5, 2011

validating dynamic controls using jquery

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

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

    $(function() {
    $('input').each(function() {
     $('#' + this.id).live('onchange', function() {  
            // VALIDATION Code
        });
    });
    
    Chad Grant : live() does not support change yet :(
    Amr ElGarhy : So i think @Deviant answer below will work
  • <%    
            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());
       });
    });
    

0 comments:

Post a Comment