Tuesday, January 12, 2021

Using JQuery to Show And Hide Button Depend on Textbox Value in ASP.NET GridView

 <script type="text/javascript">

        $(document).ready(function() {

        $("table[id*=MyGridViewID] input[type=text][id*=MyTextboxID]").keyup(function(event) {
            var elem =  $("#"+ event.target.parentNode.parentNode.cells[7].children[0].id);
        if ($("table[id*=MyGridViewID] input[type=text][id*=MyTextBoxID]").val() != '') {
           elem.fadeIn();
                }
                else {
                   elem.fadeOut();

                }

            });
        });
</script>

try this Though surely there can be easier way to achieve the same like

<script type="text/javascript">
        $(document).ready(function() {

        $("table[id*=MyGridViewID] input[type=text][id*=MyTextboxID]").keyup(function(event) { 
             var targetElem = $(this);
            /* 
             *var elem =  $("#"+ event.target.parentNode.parentNode.cells[7].children[0].id);
             * same can be done like
             */
              var elem =  $($(targetElem.parents(1)).children("td").get(7)).children().get(0).id;
        if (targetElem.val() != '') {
           elem.fadeIn();
                }
                else {
                   elem.fadeOut();

                }

            });
        });
</script>

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...