1)我通过点击主页面(index.aspx)上的一个ImangeButton 按钮来打开(显示)登录窗体Login.aspx, 当我点击按钮时Login.aspx窗体显示一下就index.aspx 和 Login.aspx 都被退出来了(被关掉了),怎么让Login.aspx 保持显示?
2)为什么在Login.aspx 的标题兰上没有窗体标题呢?(标题兰上只有 --网页对话框)。
-------------------------------------------------------------------------------
Login.aspx:
<HTML>
<HEAD>
<title>Login</title>
<body MS_POSITIONING="GridLayout" onload=OpenLoginWindow()>
<script language="javascript">
function OpenLoginWindow()
{
   windowWidth = screen.width;
   windowHeight = screen.height;
   window.showModalDialog("login.aspx",'',"dialogWidth:420px;dialogHeight:240px;dialogTop: "+( windowHeight-300)/2+"; dialogLeft: "+( windowWidth-320)/2+";center:no;status:no;scroll:no");
   window.opener = null;
   window.close();
}
</script>
</body>
</HEAD>
</HTML>------------------------------------------------------------------------------
index.aspx.csprivate void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
   Response.Redirect("Login.aspx");
}

解决方案 »

  1.   

    window.opener = null;
       window.close();这两行去掉
      

  2.   

    修改一下:
    <script language="javascript">
    function OpenLoginWindow()
    {
       windowWidth = screen.width;
       windowHeight = screen.height;
       window.showModalDialog("login.aspx",'',"dialogWidth:420px;dialogHeight:240px;dialogTop: "+( windowHeight-300)/2+"; dialogLeft: "+( windowWidth-320)/2+";center:no;status:no;scroll:no");
    }
    </script>
      

  3.   

    对你的代码更改了一下:
    对index.aspx:注册ImageButton1单击事件
    this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow()");<script language="javascript">
    function OpenLoginWindow()
    {
       windowWidth = screen.width;
       windowHeight = screen.height;
       window.showModalDialog("login.aspx",'',"dialogWidth:420px;dialogHeight:240px;dialogTop: "+( windowHeight-300)/2+"; dialogLeft: "+( windowWidth-320)/2+";center:no;status:no;scroll:no");
       window.opener = null;
       window.close();
    }
    </script>
    对Login.aspx:
    单击退出按扭时执行如下 JS:
    function btnclose()
    {
      window.returnValue = null;//这里可以写本登陆窗体的返回值
      window.close();
    }
      

  4.   


    刚才 Ctrl+C 多了些代码
    需要把上面的
    OpenLoginWindow中的
       window.opener = null;
       window.close();
    两行去掉
      

  5.   

    to: wj2929(*ヤRěйヤ*) 
    你上面修改的代码和我留的代码没什么两样
    我已去掉了这两行 :  window.opener = null;
                         window.close();
    你觉得this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow()");和
    ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {Response.Redirect("Login.aspx");} 有区别吗?我认为没有区别,前者是在事件驱动中调用OpenLoginWindow() JS函数,而后者是到开Login.aspx 也,该页一旦被到开,肯定运行那个js函数。你说呢?
      

  6.   

    更改你的代码主要是你写的Response.Redirect("Login.aspx");有问题
      

  7.   

    我已去掉了这两行 :  window.opener = null;
                         window.close();
    并在ImageButto1的OnClick事件里写了你的代码 this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow()"); 运行单击按钮后也没有打开Login.aspx反而出错。(我的感觉是脚本错误)
      

  8.   

    不是在ImageButto1的OnClick事件里添加代码 this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow()"); 而是在page_load中添加private void Page_Load(object sender, System.EventArgs e)
    {
    this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow();return false;"); 
    }
      

  9.   

    脚本有问题,??为什么要这么复杂呢?-----index.aspx------<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="Jessup.Test2" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Test2</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <style>A {
    COLOR: #000000; TEXT-DECORATION: underline
    }
    A:hover {
    COLOR: #808080; TEXT-DECORATION: none
    }
    </style>
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体"></FONT>&nbsp; <FONT face="宋体"><a style="cursor:hand" 
    onclick='window.open("Login.aspx","a","width=430,height=330,scrollbars=1")'>登陆</a></FONT>
    </form>
    </body>
    </HTML>
    ------login.aspx----------<%@ Page language="c#" Codebehind="Login.aspx.cs" AutoEventWireup="false" Inherits="Jessup.Login" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Login</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <P>
    <asp:Label id="Label1" runat="server">Label</asp:Label></P>
    <P>
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
    <P>
    <asp:TextBox id="TextBox2" runat="server"></asp:TextBox></P>
    <P>
    <asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
    <P>&nbsp;</P>
    </form>
    </body>
    </HTML>
    就这样吧
      

  10.   

    补充一下不要 scrollbars 就把他设置成 0 吧,有时候用function 并不明智
      

  11.   

    window.close();就是关闭窗体嘛,当然会关掉啦
      

  12.   

    我在主页面index.aspx上的ImageButton1的Onclick事件里写了下列代码后就可以让用户验证的登录窗体Login.aspx正常显示,才解决了这个问题又崩出新问题来了。 我在Login.aspx上输入用户名和密码并点击《确定》按钮后跳转到目标页上了,但Login.aspx窗体仍在显示,验证通过后为什么不能自动关闭呢?index.aspx.cs :private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    Page.RegisterStartupScript("Login.aspx","<script lanuage='javascript'>window.showModalDialog('login.aspx','','dialogWidth:420px;dialogHeight:240px;dialogTop: '+( screen.height-300)/2+'; dialogLeft: '+(screen.width-320)/2+';center:no;status:no;scroll:no');</script>");
    }
    -------------------------------------------------------------------------
    Login.aspx.cs :private void OkButton_Click(object sender, System.EventArgs e)
    {
      //这段代码,从数据表中依次读取 UserName 和 Password 两个字段的值并与用户输入的相应的值比较来验证该用户是否合法。
      string user=Request.Form["NameBox"].ToString();
      string pass=Request.Form["PasswordBox"].ToString();
      string cmdstr="select * from pic_user where UserName='"+Request.Form["NameBox"].ToString()+"'and Password='"+Request.Form["PasswordBox"].ToString()+"'";
      oleDbConnection1.Open();
      oleDbDataAdapter1.SelectCommand.CommandText=cmdstr;
      dataReader=oleDbDataAdapter1.SelectCommand.ExecuteReader();
      if(dataReader.Read())
      {
        string tempname=dataReader.GetString(0);
        string temppass=dataReader.GetString(1);Session.Add("user",tempname);
        Session.Add("pass",temppass);
        Session["UserName"]=tempname;
        Session["UserPass"]=temppass;
        oleDbConnection1.Close();
        Response.Redirect("AddNewImage.aspx",true);
      }
      else
      {
         Response.Write("<script>alert('用户名和密码不匹配,请重新输入!')</script>");
         oleDbConnection1.Close();
      }
    }
      

  13.   

    把window.close()去掉吧,要不就把showmodaldialog换成window.open