简体   繁体   中英

How can I call LinkButton OnClick Event from JavaScript?

In my case a have a LinkButton on the page:

<asp:LinkButton ID="LinkButton5" runat="server" OnClick="LinkButton5_Click">Delete</asp:LinkButton>

When a user clicks it, the choosen file is deleted. And to make it easy to use I added a HotKey JavaScript:

<script type="text/javascript" src="Java/Jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="Java/Jquery.hotkeys-0.7.9.js"></script>

<script type="text/javascript">
    function domo() {
        jQuery('#platform-details').html('<code>' + navigator.userAgent + '</code>');
        jQuery(document).bind('keydown', 'esc', function (evt) { alert("ESC"); return false; });
        jQuery(document).bind('keydown', 'space', function (evt) { alert("SPACE"); return false; });
        jQuery(document).bind('keydown', 'del', function (evt) { alert("DEL"); return false; });
    }

    jQuery(document).ready(domo);
</script>

So, ones you press Delete Button on your KeyBoard JavaScript alerts you that it was clicked. :) I need ones I click Del Button LinkButton5 should be clicked. I dont realy know how I can connect the javascript call the folowing OnClick event. Please Help!

you can use the following code..

add the code after you alert('DEL');

var btn = document.getElementById('<%=LinkButton5.ClientID%>');
btn.click();
document.getElementById('<%=LinkButton5.ClientID%>').click();

尝试将此行添加到脚本文件

jQuery(document).bind('keydown', 'del', function (evt) { alert("DEL");$('#<%=LinkButton5.ClientID%>').trigger('click'); return false; });

Replace:

alert("DEL"); return false;

With

<%= ClientScript.GetPostbackEventReference(LinkButton5, null) %>

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