0

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();
        });
Zaki
  • 5,540
  • 7
  • 54
  • 91

5 Answers5

4

Because your LinkButtons 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.

Rawling
  • 49,248
  • 7
  • 89
  • 127
  • tried this but i dont see the disable attribute using firefox – Zaki Dec 06 '12 at 09:49
  • The problem could also be that maybe you can't disable a link button? Try a literal `.Remove()` and see if the buttons disappear or not. – Rawling Dec 06 '12 at 09:52
  • cool this works now with hide() function $('[id*=lnkbtn_Remove]').hide('slow'); – Zaki Dec 06 '12 at 09:53
  • Great, so the selector works at least; I think however you can only _disable_ a `LinkButton` by e.g. clearing out its `OnClick` behaviour. – Rawling Dec 06 '12 at 09:57
2

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(); 
Abhijit Pandya
  • 705
  • 2
  • 12
  • 33
1

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);
Adil
  • 146,340
  • 25
  • 209
  • 204
  • I can see the disabled attribute in firebug on button set to true after click but still am able to click the button.. – Zaki Dec 06 '12 at 09:46
  • AFAIK To disable anchor you need to remove attribute href or use preventDefault on its click – Adil Dec 06 '12 at 09:57
1

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');
Schnapz
  • 1,208
  • 13
  • 10
0
$('#lnkbtn_Remove').click(function(){return false;})
Boriss Pavlovs
  • 1,441
  • 12
  • 8