ASP.NET WebForms + Postback 然后打开弹出窗口 [英] ASP.NET WebForms + Postback then open popup

查看:18
本文介绍了ASP.NET WebForms + Postback 然后打开弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须回发以执行某些逻辑的 LinkBut​​ton.

I have a LinkButton that has to postback to perform some logic.

完成后,我不想在浏览器中重新加载页面,而是想不理会它并弹出一个新窗口.

Once it is finished, instead of loading the page back up in the browser, I want to leave it alone and pop open a new window.

到目前为止,我最好的想法是将 LinkBut​​ton 放在 UpdatePanel 中,并让它在重新加载时呈现一些 JavaScript,但我认为这完全是 hacky.另外,如果我没记错的话,更新面板中的 JavaScript 无论如何都不会运行.

So far, the best idea I've had is to put the LinkButton in an UpdatePanel, and have it render some JavaScript out when it reloads, yet I think that is totally hacky. Also, if I recall right, JavaScript within a update panel won't run anyways.

还有其他想法吗?

推荐答案

使用 LinkBut​​ton.PostBackUrl 将不同的页面设置为 POST 到,并使用一些客户端脚本来获取新窗口(并恢复旧目标以便将来回发工作一般).第二页可以使用 PreviousPage 从原始页面访问任何需要的状态.

Use LinkButton.PostBackUrl to set a different page to POST to, and some client script to get a new window (and the old target restored so that future postbacks work normally). The 2nd page can use PreviousPage to get access to any needed state from the original page.

<script runat="server">
   void lnk_Click(object sender, EventArgs e) {
      // Do work
   }
</script>

<script type="text/javascript">
   var oldTarget, oldAction;
   function newWindowClick(target) {
      var form = document.forms[0];
      oldTarget = form.target;
      oldAction = form.action;
      form.target = target;

      window.setTimeout(
         "document.forms[0].target=oldTarget;"
         + "document.forms[0].action=oldAction;", 
         200
      );
   }
</script>

<asp:LinkButton runat="server" PostBackUrl="Details.aspx" Text="Click Me"
  OnClick="lnk_Click"
  OnClientClick="newWindowClick('details');" />

这篇关于ASP.NET WebForms + Postback 然后打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆