Button加入的确认删除对话框,点击取消后,照样删除,为什么呢?
function IsChecked()
{
var GridView1=document.getElementById( " <%=GridView1.ClientID %> ");
var flag=false;
for(i = 1;i < GridView1.rows.length; i++)
{
if(GridView1.rows[i].cells[0].getElementsByTagName( "INPUT ")[0].checked)
{
flag=true;
break;
}
}
if(!flag)
{
alert( "请选择被删除的记录 ");
return false;
}
if(confirm( "确定要删除选中的记录吗? "))
return true;
else
return false;
}
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " DataKeyNames= "nid ">
......
</asp:GridView>
<asp:Button ID= "Button3 " runat= "server " Text= "删除选中的记录 " OnClientClick= "return IsChecked() "onClick= "Button3_Click " />
protected void Button3_Click(object sender, EventArgs e){......;//获取ID;DelDetails(ID);}
private void DelDetails(int id){....}
我在GridView中加入了 <asp:CheckBox ID= "check " runat= "server " Text= "选择 " />
加入的确认删除对话框,点击取消后,照样删除,为什么呢?
------解决方案--------------------private void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
btnDel.Attributes.Add( "onClick ", "if (!window.confirm( '您真的要删除这条记录吗? ')){return false;} ");
}
}