为什么我的confirm验证控件第二次点后才好使?
我的程序是C#写的,webform,我想鼠标点击Button1时能弹出来一个确认框,可是第一次点的时候,直接就更新数据库了,然后再点就能弹出来这个确认框了,不知道怎么回事,请各位大侠帮忙,谢谢!下边是我的代码。
private void Button1_Click(object sender, System.EventArgs e)
{
string updatestoptime;
try
{
DateTime.Parse(TextBoxStopTime.Text);
updatestoptime = TextBoxStopTime.Text;
string connsource =" Provider=SQLOLEDB.1;Password=exchange;User ID=exchange;Initial Catalog=exchange2;Data Source=localhost;";
OleDbConnection conn1 = new OleDbConnection(connsource);
conn1.Open();
string userid = GetPubCookie("userid");
string Fcity,FName,Fnum;
Fcity = City(LabelCity.Text);
FName = DName(LabelDJName.Text);
Fnum = Dtelleading(LabelTelleading.Text);
string updatesql="";
Dropdownlist4.SelectedItem.Text + "-" + Dropdownlist5.SelectedItem.Text;
updatesql="update telephonetoprocess set exectime = '" + updatestoptime + "' " +
" where 1=1 " + Fcity + FName + Fnum + " and datepart(year,deal_date)='" + LabelTime.Text +" ' and datepart(month,deal_date)='" + LabelMonth.Text +" '" +
" and remark in ('A2','A4')";
OleDbCommand MyCommand_update=new OleDbCommand(updatesql,conn1);
Button btn = (Button)Page.FindControl("Button1");
btn.Attributes.Add("onclick", "return confirm('你是否确定修改停机时间为"+ updatestoptime +"这条记录?');");
MyCommand_update.ExecuteNonQuery();
Response.Write("<script>alert(\"停机时间修改成功!\");</script>");
}
catch
{
Response.Write("<script>alert(\"请输入时间,格式为“yyyy-mm-dd”!\");</script>");
}
}