【问题标题】:ASP.NET Button with no code reloads page in a new window when clicked单击时没有代码的 ASP.NET 按钮在新窗口中重新加载页面
【发布时间】:2011-09-22 21:07:28
【问题描述】:

我有一个非常简单的 ASP.NET 项目。它由两页组成。

第一页 (FirstPage.htm) 有以下标记:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <script type="text/javascript">
            function test() {
                window.showModalDialog('PageTwo.aspx', '', '');
            };
        </script>
</head>
<body>
    <a href="#" onclick="test();">Test Window</a>
</body>
</html>

第二页(PageTwo.aspx)有这个作为标记:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="PageTwo.aspx.vb" Inherits="MyEmptyWebApp.PageTwo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Button ID="Button1" runat="server" Text="Button 1" />


    </div>
    <asp:Button ID="Button2" runat="server" Text="Button 2" />
    </form>
</body>
</html>

这就是 CodeBehind:

Public Class PageTwo
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

End Class

所以第一页有一个超链接,可以在弹出窗口中加载第二页。

第 2 页有一个按钮,应该什么都不做。但是,当我单击按钮时,会弹出一个新窗口并再次加载第 2 页。

如果我直接导​​航到第 2 页,什么都不会发生。

我想我必须在 VS 或 IIS 中有一些奇怪的配置导致它;但我不知道是什么。

解决方法是here如果你想下载看看。

【问题讨论】:

    标签: javascript asp.net html vb.net


    【解决方案1】:

    模态对话窗口无法处理 asp.net 回发。看看这个链接

    http://www.eggheadcafe.com/tutorials/aspnet/96c46e09-b383-4330-ae8d-99436cb6c330/aspnet-modaldialog-with-postback-and-return-values-to-parent-page.aspx

    希望对你有帮助

    ps - 这里是msdn 了解更多关于模态对话的信息

    【讨论】:

      【解决方案2】:

      关闭按钮上的AutoPostback 属性。

      【讨论】:

      • 为什么会在新窗口中打开?
      猜你喜欢
      • 2013-05-06
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2019-10-26
      • 2013-10-13
      • 2023-03-13
      相关资源
      最近更新 更多