ASP.NET WebForms + Postback 然后打开弹出窗口

ASP.NET WebForms + Postback then open popup(ASP.NET WebForms + Postback 然后打开弹出窗口)
本文介绍了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 然后打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)