简体   繁体   中英

Onclick for a LinkButton

The button:

<asp:LinkButton ID="ShowEventUnusualByDate" OnClick="ShowEventUnusualByDate_Click" CssClass="btn" runat="server"><i class="la la-check"></i>GO</asp:LinkButton>

And afterward the jQuery:

$('#Main_ShowEventUnusualByName').click(function () {
    $(this).css('color', 'red');
});

But on click, nothing appears to happen.

The main problem is you are taking wrong ID in jquery selector, because the button ID is some different.

I have checked it two ways:

  1. Taking a simple button of HTML and changing the text color on click - Passed .

  2. Taking your ASP.Net server control button in my IDE (for test purpose) - Passed

Please note: If you run the snippet you might get error because SO code editor doesn't support asp.net server controls. You must check it on your Visual Studio IDE only.

 $('#ShowEventUnusualByDate').click(function() { $(this).css('color', 'red'); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <asp:LinkButton ID="ShowEventUnusualByDate" OnClick="ShowEventUnusualByDate_Click" CssClass="btn" runat="server"><i class="la la-check"></i>GO</asp:LinkButton>

Hope this helps.

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