开发者

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

开发者 https://www.devze.com 2023-04-13 10:00 出处:网络
I have an asp:LinkButton which require following - - call jQuery to open link u开发者_StackOverflow中文版rl in another tab of current browser

I have an asp:LinkButton which require following -

- call jQuery to open link u开发者_StackOverflow中文版rl in another tab of current browser

- 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

  • an efficient and user friendly way of calling server side method (where I can avoid postback)

Thank you!


Having Javascript make a call like:

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?

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.

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"
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号