简体   繁体   English

.net-单击asp:LinkBut​​ton调用客户端和服务器端方法

[英].Net - call client side and server side method on click of asp:LinkButton

I have an asp:LinkButton which require following - 我有一个asp:LinkBut​​ton需要以下内容-
- call jQuery to open link url in another tab of current browser -调用jQuery在当前浏览器的另一个选项卡中打开链接URL
- then call server side method to perform some logging stuff -然后调用服务器端方法来执行一些日志记录工作

Please guide me for a 请指导我

  • safe (which can help avoid having 'popup blocked' messages as far as possible), I understand I shouldn't override any user personal setting for popup blocker but as it is a direct user click on asp:LinkButton, was wondering if there is a neat solution to avoid Popup blocker messages and 安全(这有助于尽可能避免“弹出窗口被阻止”消息),我了解我不应该覆盖弹出窗口阻止程序的任何用户个人设置,但因为它是直接用户单击asp:LinkBut​​ton,所以想知道是否存在避免弹出窗口阻止程序消息的整洁解决方案,以及

  • an efficient and user friendly way of calling server side method (where I can avoid postback) 调用服务器端方法的一种高效且用户友好的方式(可以避免回发)

Thank you! 谢谢!

Having Javascript make a call like: 使用Java进行呼叫,例如:

window.open("http://www.google.com");

will always run the risk of being caught by a popup blocker. 总是有被弹出窗口阻止程序捕获的风险。 Is there a reason why you can't just set target="_blank" on the <a> tag? 为什么不能仅在<a>标记上设置target =“ _ blank”?

As far as calling a server-side method without doing a postback, it's not possible. 至于不执行回发而调用服务器端方法,则是不可能的。 You could use JQuery's ajax function to make a call to a server side method where the page doesn't refresh, but a post-back must still occur, whether it is visible to the user or not. 您可以使用JQuery的ajax函数调用不刷新页面的服务器端方法,但是无论用户是否可见,都必须进行回发。

Here is what that looks like: 看起来像这样:

$.ajax({
  type: 'POST',
  url: "http://www.yourdomain.com/pageToPostTo.aspx",
  data: "your data here",
  success: function(data) {
     alert("It worked");
  },
  dataType: "json"
});

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

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