ASP.NET WebForms + Postback then open popup(ASP.NET WebForms + Postback 然后打开弹出窗口)
问题描述
我有一个必须回发以执行某些逻辑的 LinkButton.
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.
到目前为止,我最好的想法是将 LinkButton 放在 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.
还有其他想法吗?
推荐答案
使用 LinkButton.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 然后打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET WebForms + Postback 然后打开弹出窗口


基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01