日期:2014-05-18  浏览次数:20415 次

请帮忙看看,为什么网页中的一个新增记录按钮,点击时却弹不出新增页面呢?(单独运行新增页面是没有问题的)
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  Dim ntype As String = DropDownList1.SelectedValue.ToString '--类型 
  Response.Write("<script>window.open('newadd.aspx?ctype=" + ntype.ToString + "','Add','menubar=no,toolbar=no,location=no,directories=no,status=yes,width=740,height=400,left='+(window.screen.width-550)/2+',top='+(window.screen.height-350)/2+',scrollbars=yes')</script>")
   
  End Sub

以上是我网页中的一个按钮的代码,但是运行时却没有弹出新的页面, 也没有报错!,而我单独运行那个新增页面newadd.aspx则可以. 请指教,谢谢!

------解决方案--------------------
嗯,我写了两个,一个HyperLink,一个Button。关键是不需要把代码写到回发流程中去,那样显得把本来很少的动作做得很复杂。

HTML code
<%@ Page Language="C#" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.HyperLink1.Attributes["onclick"] = "this.href+=document.getElementById('" + this.DropDownList1.ClientID + "').value;";
            DropDownList1.SelectedValue = "s1";
            this.Button1.OnClientClick = "window.open('newadd.aspx?ctype='+ document.getElementById('" + this.DropDownList1.ClientID +
                "').value,'Add','menubar=no,toolbar=no,location=no,directories=no,status=yes,width=740,height=400,left='+(window.screen.width-550)/2+',top='+(window.screen.height-350)/2+',scrollbars=yes');return false;";
        }
    }
</script>

<!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">
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem>s1</asp:ListItem>
        <asp:ListItem>s2</asp:ListItem>
        <asp:ListItem>s3</asp:ListItem>
    </asp:DropDownList>
    <asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl="~/abc.aspx?xx=" CssClass="按钮样式">Click Me 1</asp:HyperLink>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
</body>
</html>

------解决方案--------------------
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click 
Dim ntype As String = DropDownList1.SelectedValue.ToString '--类型 
Response.Write(" <script>window.open('newadd.aspx?ctype=" + ntype.ToString + "','Add','menubar=no,toolbar=no,location=no,directories=no,status=yes,width=740,height=400,left='+(window.screen.width-550)/2+',top='+(window.screen.height-350)/2+',scrollbars=yes') </script>") 

End Sub 
改成下面的看看:
 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click 
Dim ntype As String = DropDownList1.SelectedValue.ToString '--类型 
Response.redirect(" <script>window.open('newadd.aspx?ctype=" + ntype.ToString + "','Add','menubar=no,toolbar=no,location=no,directories=no,status=yes,width=740,height=400,left='+(window.screen.width-550)/2+',top='+(window.screen.height-350)/2+',scrollbars=yes') </script>")
End Sub 


------解决方案--------------------
估计是禁止了弹出窗口吧