简体   繁体   English

如何从客户端调用服务器端ASP.NET事件

[英]how to call a server-side ASP.NET event from the client-side

I have an asp.net button in the gridview footer, and I wanna to call the server-side ASP.NET button event in the client side (JavaScript). 我在gridview页脚中有一个asp.net按钮,我想在客户端(JavaScript)中调用服务器端ASP.NET按钮事件。

How to do this please code details if possible. 如何执行此操作,请在可能的情况下编码详细信息。

My .aspx: 我的.aspx:

<FooterTemplate>
    <asp:ImageButton ID="ibtn_add" ImageUrl="~/Images/accord_plus.png" 
         runat="server" OnClick="ibtn_add_Click" />
</FooterTemplate>

I wanna to know how to call the ibtn_add_Click in the client side. 我想知道如何在客户端调用ibtn_add_Click

in the following code: 在以下代码中:

var isShift = false;
document.onkeyup = function(e)
{ if (e.which == 16) isShift = false; }
document.onkeydown = function(e) {
    if (e.which == 16) isShift = true;
    if (e.which == 13 && isShift == true) {
        //Here I wanna to call ibtn_add_Click
        return false;
    }
}

Note : 注意 :

The gridview in an update panel, and I execute the JavaScript through: 在更新面板中的gridview中,我通过以下方式执行JavaScript:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/Scripts/Shortcut.js" />
    </Scripts>
</asp:ScriptManager>

Use OnClientClick button's attribute. 使用OnClientClick按钮的属性。

OnClientClick="ibtn_add_Click()"

MSDN MSDN

I think you want something like this ... 我想你想要这样的东西...

if (e.which == 13 && isShift == true) 
{ 
    __doPostBack('ibtn_add','OnClick');
    return false; 
} 

You might use ajax and make a call to webservice or web method or you can use or you can use 您可能使用ajax并调用了Web服务或Web方法,或者可以使用或者可以使用

 __doPostBack(‘btntest','OnClick')

or 要么

 $('btntest').trigger('click');

chck this link : http://codethatworkedforme.blogspot.com/2011/08/some-tricks-for-asynchronous-postback.html 单击此链接: http ://codethatworkedforme.blogspot.com/2011/08/some-tricks-for-asynchronous-postback.html

 <asp:ImageButton ID="ibtn_add" ImageUrl="~/Images/accord_plus.png" runat="server" OnClick="ibtn_add_Click" />

这是我遇到的问题,但仅用于OnClientClick

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ASP.NET中从客户端调用服务器端函数? - How to call server-side function from client-side in ASP.NET? 从服务器端asp.net注册客户端json的有效方法? - Efficient way to register client-side json from server-side asp.net? 如何在 ASP.NET Core 3.1 MVC 中进行RequiredIf 客户端和服务器端验证? - How to make RequiredIf Client-side and server-side validation in ASP.NET Core 3.1 MVC? ASP.NET双列表框使用JQuery更新了客户端,以及如何在服务器端检索结果 - ASP.NET dual listboxes updated client-side with JQuery, and how to retrieve the results server-side ASP.NET客户端与服务器端验证 - ASP.NET Client-side vs Server-side Validation 客户端(jquery)和服务器端(asp.net)应用程序都可以访问的服务 - Service that can be accessed by both client-side (jquery) and server-side (asp.net) applications Asp.Net:在服务器端还原DropDownList的客户端SelectedItem - Asp.Net: Restoring client-side SelectedItem of DropDownList on server-side 结合 Asp.Net Core 服务器端和 React 客户端 - Combining Asp.Net Core server-side and React client-side 在客户端加密ASP.NET文本字段,并在服务器端解密 - Encrypting ASP.NET text fields at client-side and decrypting them at server-side 用于客户端和服务器端验证的 ASP.NET Core 重用代码 - ASP.NET Core Reuse Code for Client-Side and Server-Side Validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM