关闭当前页面:<a href="javascript:window.opener=null;window.close();">关闭</a>,如果是按钮则:
Response.Write("<script language=/"javascript/">window.opener=null;window.close();</script>");
这样点关闭的时候就不会弹出如当前窗口正试图关闭的对话框了.
那么怎么样当用户点浏览器的最大化最小化关闭按钮中的关闭按钮时也弹出关闭的确认对话框呢?这样:
<body οnbefοreunlοad="return '真的要关闭此窗口吗?'">这样的话在点关闭时候就会执行onbeforeunload函数,弹出真的要关闭此窗口吗的对话框,点取消返回假,不关闭,点确定返回真关闭窗口
那么怎么样才能够点击某个按钮的时候弹出确定取消对话框呢??如果点取消就不执行下面的代码,点确定就继续执行下面的代码?
在按钮的单击里写:
Response.Write("<script language=/javascript/">" + "if(confirm(/"确定吗?/"))"+"{window.location.href='default.aspx';}"+"else{history.back();}"+"</script>");
意思是:首先用confirm函数弹出个有确定取消的对话框,如果你点了确定就返回真,就执行window.location.href='default.aspx'代码,如果点了取消就返回假,就执行history.back();返回到原来的页面
当然我们也可以这样写:
private void btnChong_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Write("<script language=/"javascript/">" + "if(!confirm(/"您确定要充值吗?/"))" + "{history.back();}" + "</script>");
//首先弹出一个含有确定取消按钮的对话框,如果点取消,则返回原页面,将不执行下面所有代码
string connString = ConfigurationSettings.AppSettings["connStr"].ToString() + Server.MapPath(Request.ApplicationPath) +"//hualong.mdb";
OleDbConnection conn = new OleDbConnection(connString);
string selString = "select Count(*) from myuser where name = @name";
OleDbCommand comm = new OleDbCommand(selString,conn);
conn.Open();
comm.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,50));
comm.Parameters["@name"].Value = txtZhang.Text.ToString().Trim();
int i = (int)comm.ExecuteScalar();
conn.Close();
if(i==0)//如果帐号不存在
{
Response.Write("<script>alert('帐号不正确!')</script>");
return;//return下面的所有代码将不会被执行
}
else//如果帐号存在再执行下面的代码
{
string selString1 = "select Count(*) from haoma where kahao = @kahao and mima = @mima and youxiao = '有效'";
OleDbCommand comm1 = new OleDbCommand(selString1,conn);
conn.Open();
comm1.Parameters.Add(new OleDbParameter("@kahao",OleDbType.VarChar,50));
comm1.Parameters.Add(new OleDbParameter("@mima",OleDbType.VarChar,50));
comm1.Parameters["@kahao"].Value = txtKa.Text.ToString().Trim();
comm1.Parameters["@mima"].Value = En.Encryption(txtPass.Text.ToString().Trim(),"16899168");//把密码加密
int ii = (int)comm1.ExecuteScalar();
conn.Close();
if(ii==0)//如果卡记录不存在或者已经被充值
{
Response.Write("<script language=/"javascript/">alert('卡号或者密码错误!');</script>");
return;//不执行下面的代码
}
else
{
string selStr = "select over_date from myuser where name = @name";
//把myuser表里面的用户过期字段取出来
OleDbCommand comm11 = new OleDbCommand(selStr,conn);
conn.Open();
comm11.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,50));
comm11.Parameters["@name"].Value = txtZhang.Text.ToString().Trim();
OleDbDataReader dr = comm11.ExecuteReader();
dr.Read();
DateTime overDate = new DateTime();
overDate = dr.GetDateTime(0);
dr.Close();
conn.Close();
string upString = "update haoma set youxiao = '无效',zhanghao = @zhanghao,ch_date = @ch_date where kahao = @kahao";
//更新数据库记录使卡号处于失效状态,同时写入用户充值记录
string upString1 = "update myuser set over_date = @over_date where name = @name";
//更新数据记录用户帐户过期日加一个月
OleDbCommand comm22 = new OleDbCommand(upString,conn);
conn.Open();
//comm22.Parameters.Add(new OleDbParameter("@youxiao",OleDbType.VarChar,50));
comm22.Parameters.Add(new OleDbParameter("@zhanghao",OleDbType.VarChar,50));
comm22.Parameters.Add(new OleDbParameter("@ch_date",OleDbType.Date));
comm22.Parameters.Add(new OleDbParameter("@kahao",OleDbType.VarChar,50));
comm22.Parameters["@zhanghao"].Value = txtZhang.Text.ToString().Trim();
comm22.Parameters["@ch_date"].Value = DateTime.Now;
comm22.Parameters["@kahao"].Value = txtKa.Text.ToString().Trim();
comm22.ExecuteNonQuery();
conn.Close();
OleDbCommand comm33 = new OleDbCommand(upString1,conn);
comm33.Parameters.Add(new OleDbParameter("@over_date",OleDbType.Date));
comm33.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,50));
comm33.Parameters["@name"].Value = txtZhang.Text.ToString().Trim();
if(overDate > DateTime.Now)
{
comm33.Parameters["@over_date"].Value = overDate.AddMonths(1);
}
else
{
comm33.Parameters["@over_date"].Value = DateTime.Now.AddMonths(1);
}
conn.Open();
comm33.ExecuteNonQuery();
conn.Close();
Response.Write("<script language=/"javascript/">alert('充值成功,祝学习创业愉快!');</script>");
}
}
}