注册 登录
编程论坛 ASP.NET技术论坛

window.close() 问题

yunj1105 发布于 2007-05-22 16:22, 654 次点击
'Default2.aspx'
protected void Button1_Click(object sender, EventArgs e)
{
string str = "<script language='javascript' defer>ret = window.showModalDialog('Default3.aspx',window,'dialogHeight:250px;dialogWidth:600px;center:Yes;Help:No;Resizable:No;Scroll:auto;Status:no;');</script>";
Response.Write(str);
}
Default3.aspx
protected void Button1_Click(object sender, EventArgs e)
{
string str1 = "<script language='javascript'>window.close();</script>";
Response.Write(str1);
}
为什么从'Default2.aspx'跳转到'Default3.aspx'时,点了button'Default3.aspx'不会关闭呢?
2 回复
#2
islet2007-05-22 16:26
关闭按钮没必要让服务器端处理
就用普通按钮
<button onclick="window.close()">关闭</button>
#3
yunj11052007-05-22 16:34
是因为button还有一些其他操作数据库的功能
Default3.aspx
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox2.Text == "" || TextBox3.Text == "")
{
Response.Write("<script defer>alert('请输入专业ID与名称!');</script>");
return;
}
if (Request["action"] == "edit")
{
string strCmd = "update lab_major set dept_id='" + DropDownList1.SelectedValue + "',major_ID='" + TextBox2.Text + "',major_name='" + TextBox3.Text + "' where major_num like '" + Request["majornum"] + "";
co_major_add.ENQ(strCmd);
}
else
{
string strC = "select * from lab_major where major_id like'" + TextBox2.Text + "' or major_name like'" + TextBox3.Text + "'";
object a = co_major_add.EXS(strC);
if (a == null)
{
string strCmd1 = "insert lab_major (major_id,major_name,dept_ID) values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + DropDownList1.SelectedValue + "')";
co_major_add.ENQ(strCmd1);
Response.Write("<script defer>alert('添加成功!');</script>");

}
else
{
Response.Write("<script defer>alert('您输入的已存在,请重新输入!');</script>");
}
}
string str1 = "<script language='javascript'>window.dialogArguments.document.location.href='Major.aspx';window.close();</script>";
Response.Write(str1);
}
1