当前位置: 代码迷 >> ASP.NET >> gridview 弹出确认对话框 为什么还提交了?该怎么处理
  详细解决方案

gridview 弹出确认对话框 为什么还提交了?该怎么处理

热度:6723   发布时间:2013-02-25 00:00:00.0
gridview 弹出确认对话框 为什么还提交了??
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  //如果是绑定数据行
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
  {
  ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
  }
  }

  }

为什么数据还是被删除了???

------解决方案--------------------------------------------------------
我以前写的.
JScript code
    在使用window.confirm时发现,在不同的浏览器中,其它返回值是不同的,IE7.0中,如果点击"取消",返回值returnValue并不是false,但在Mathon浏览器中是返回false值.      如果正确的语法应该是:if(!window.confirm("确定要注销吗?")){event.returnValue=false;}就能返回正确的值,且不能写成:if(window.confirm("确定要注销吗?")){event.returnValue=true;}这样返回结果在不同浏览器也是不一样的!
------解决方案--------------------------------------------------------
C# code
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)            {                ((Button)e.Row.Cells[2].Controls[0]).Attributes["onclick"] = "if(!confirm('你真的要删除" + e.Row.Cells[3].Text + "这条记录么?'))return   false;";            }        }    }
------解决方案--------------------------------------------------------
会提交???
我也是IE,不会提交,IE6 IE7都不会提交
探讨
<form method="get">
<input type="submit" name="a1" onclick="return false">
</form>

这个是会提交的

------解决方案--------------------------------------------------------
C# code
<asp:TemplateField ShowHeader="False">                      <ItemStyle HorizontalAlign="Center" Width="100px" />                      <ItemTemplate>                         <asp:Button ID="btnDelete" runat="server" CausesValidation="False"                                 onclick="btnDelete_Click" Text="删除" Width="45px"/>                      </ItemTemplate>                  </asp:TemplateField>
  相关解决方案