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");
}
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");
}
window.close();这两行去掉
<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>
对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();
}
刚才 Ctrl+C 多了些代码
需要把上面的
OpenLoginWindow中的
window.opener = null;
window.close();
两行去掉
你上面修改的代码和我留的代码没什么两样
我已去掉了这两行 : 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函数。你说呢?
window.close();
并在ImageButto1的OnClick事件里写了你的代码 this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow()"); 运行单击按钮后也没有打开Login.aspx反而出错。(我的感觉是脚本错误)
{
this.ImageButton1.Attributes.Add("onclick","javascript:OpenLoginWindow();return false;");
}
<!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> <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> </P>
</form>
</body>
</HTML>
就这样吧
{
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();
}
}