ASP.NET的WebForms回发+然后打开弹出 [英] ASP.NET WebForms + Postback then open popup

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

问题描述

我有了回发执行一些逻辑,一个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出来时,它重新加载,但我认为这是完全哈克。另外,如果我记得没错,一个更新面板内的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设置不同的页面张贴到,有的客户端脚本来获得一个新的窗口(和恢复,以便将来回传工作的老目标一般)。第2页可以使用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回发+然后打开弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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