简体   繁体   中英

disable/hide all link button using jquery in repeater

I have a repeater which will have a link button per row here is the code:

<asp:Repeater ID="rpt_OutstandingBCsForClient" runat="server">
   <ItemTemplate>
        <div class="pay">
            <table>
                 <tr>
                     <td>
                      <div style="width: 230px;">
                <asp:Label ID="lbl_Len" runat="server" ></asp:Label>
                 </div>
                   </td>
                  <td align="left">
                  <div style="width: 80px;">
            <asp:LinkButton ID="lnkbtn_Remove" runat="server">Remove</asp:LinkButton>

            </div>
              </td>                            
               </tr>
           </table>
          </div>
        </ItemTemplate>
      </asp:Repeater>

I want to disable or hide all Linkbuttons with id 'lnkbtn_Remove' on button click, so i have done this but still it doesn't work, if put an alert after var linkButton1 I get an object, but it doesn't disable or hide the link button:

$("input[id$='btnP']").click(function (e) {
                var linkButton1 = $('[id*="lnkbtn_Remove"]'); 
                $.ajax({
                    type: "POST",
                    url: "MyPage.aspx/Take",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (msg) {
                        if (msg.d.indexOf('https://') > -1) {

                            $('#lnkbtn_Remove').attr("disabled", true);
                        }
                        else {

                        }
                    }

                });

            e.preventDefault();
        });

Because your LinkButton s are server-side controls, their client-side IDs will not be lnkbtn_Remove but somethingsomethingsomethinglnkbtn_Remove .

Thus, try $('[id$="lnkbtn_Remove"]') instead of $('#lnkbtn_Remove') . id$= means "ID ends with".


As well as the selector issue, you also apparently can't disable a LinkButton , so you need to .remove() or .hide() it.

OnbuttonClick If you want to disable this button then you can use...

$('[id*=lnkbtn_Remove]').attr("disabled", true);

or if you want to hide this then simply you can use

$("#lnkbtn_Remove").hide(); 

Your id will be changed by asp.net for each link button. Use wild cards.

Change

$('#lnkbtn_Remove').attr("disabled", true);

To

$('[id*=lnkbtn_Remove]').attr("disabled", true);

Try to set CSS class for your buttons like "linkButtonRemove", so all link buttons from your repeater will have the same class. I think it's better way than using IDs here...

And then in jquery try to hide found elements:

    $('.linkButtonRemove').hide();

or through adding css style

     $('.linkButtonRemove').css('display', 'none');
$('#lnkbtn_Remove').click(function(){return false;})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM