首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

confirm的有关问题

2012-08-22 
confirm的问题GridViewRow gvr (sender as Button).NamingContainer as GridViewRowvar pid gvr.RowI

confirm的问题
GridViewRow gvr = (sender as Button).NamingContainer as GridViewRow;
  var pid = gvr.RowIndex;
  string id = this.GridView1.DataKeys[pid].Value.ToString();
  DataTable dr = (DataTable)Session["cart"];
  TextBox txb = (TextBox)GridView1.Rows[pid].FindControl("TextBox3");
  Button bt1 = (Button)GridView1.Rows[pid].Cells[5].FindControl("Button1");
  if (txb.Text == "1")
  { 
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "if(confirm('您确定删除本商品吗?')){document.getElementById('none_text').value='1'}else{document.getElementById('none_text').value='0'}", true);
  if (none_text.Text == "1")
  {
  if (id == dr.Rows[i]["id"].ToString())
  {
  dr.Rows.RemoveAt(i);
  Response.Redirect("cart.aspx");
  }
  }
  [code=C#][/code] }
为什么点了确定之后的同时不执行下面的代码,而是再点一次才删除呢??

[解决办法]
点减号时并不将页面发送到后台,而是触发前台的js,由js弹框询问用户是否删除,如用户确定删除再将页面递交到后台,由后台在购物车中删除。js写在页面的<script>内即可。

HTML code
<scipt>function DelteGood(){if(confirm('您确定删除本商品吗?')){document.getElementById('none_text').value='1'document.forms[0].submit();  // 这里提交你需要提交的Form,如有多个Form需要填入正确的index.}else{document.getElementById('none_text').value='0'}</script> 

热点排行