首页 > 解决方案 > 从下拉列表中选择会导致页面在新窗口中打开

问题描述

我有一个使用 vb.net 的 asp.net 页面。有一个链接按钮可以在单独的选项卡中打开商店的网站。这是使用 Javascript 完成的。还有一个包含外套尺寸的下拉列表。下拉列表发回。

这是我遇到的问题。

用户单击链接按钮,将他带到单独选项卡中的商店网站。该商店的网站实际上确实出现在一个标签中。但是,“之后”用户执行此操作,如果用户从下拉列表中选择尺寸,则原始页面会在新选项卡中打开。这不应该发生。从下拉列表中选择外套尺寸不应导致原始页面在单击链接按钮后在新选项卡中打开。有人可以让我知道如何解决这个问题吗?提前致谢。

服务器代码如下。

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
    Dim size As String
    size = DropDownList1.SelectedValue
End Sub

Protected Sub LinkButton1_Click(sender As Object, e As System.EventArgs)
    Dim link As String
    link = "http://"
    link = link + "www.google.com"
    Response.Redirect(link)
End Sub

页面代码如下。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList1" runat="server" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
            <asp:ListItem>Sm</asp:ListItem>
            <asp:ListItem>Med</asp:ListItem>
            <asp:ListItem>Lg</asp:ListItem>
            <asp:ListItem>XLg</asp:ListItem>
        </asp:DropDownList>

        <br /><br />

        <asp:LinkButton ID="LinkButton1" runat="server" 
            onclick="LinkButton1_Click" OnClientClick="SetTarget();">LinkButton</asp:LinkButton>
    </form>
</body>

<script type = "text/javascript">

    function SetTarget() {
        document.forms[0].target = "_blank";
    }
</script>
</html>

标签: javascriptasp.netvb.net

解决方案


推荐阅读