2014-10-26 121 views
0

我搜索了很多..但未能实现。 这里是我的代码,我如何防止重复插入页面刷新,,(我如何使用viewstate,或任何其他方法.... resposnse.redirect不是在这种情况下的解决方案)。防止页面刷新时出现重复记录插入

protected void btn_save_click(object sender, EventArgs e) 
    { 
      System.Data.DataTable dt_plotid = new System.Data.DataTable(); 
      dt_plotid = FghBAL.Admitting.GetMax_ByPlotID(txt_plot.Text); 
      string plotid = dt_plotid.Rows[0]["ID"].ToString(); 
      if (FghBAL.Alotee.InserAllotee(txt_alotee_name.Text.ToUpper(), ddl_alotee_sw.SelectedValue.ToUpper(), txt_alotee_fname.Text.ToUpper(), alotee_cnic, txt_alotee_phone.Text, txt_alotee_cellno.Text, txt_alotee_address.Text, txt_alotee_email.Text, plotid)) 
      { 
       lbl_error_3.Visible = true; 
       lbl_error_3.Text = "Add Successfully"; 
       txt_alotee_name.Enabled = false; 
       ddl_alotee_sw.Enabled = false; 
       txt_alotee_fname.Enabled = false; 
       txt_alotee_cnic_1.Enabled = false; 
       txt_alotee_cnic_2.Enabled = false; 
       txt_alotee_cnic_3.Enabled = false; 
       txt_alotee_phone.Enabled = false; 
       txt_alotee_cellno.Enabled = false; 
       txt_alotee_address.Enabled = false; 
       txt_alotee_email.Enabled = false; 
       System.Data.DataTable dt_alotee_data = new System.Data.DataTable(); 
       dt_alotee_data = FghBAL.Alotee.GetDatabyPlot_Id(plotid); 
       grid_alotee.DataSource = dt_alotee_data; 
       grid_alotee.DataBind(); 
       grid_alotee.Visible = true; 
       btn_save_alotee.Visible = true; 

       btn_link_another_alotee.Visible = true; 
       lbl_grd_alotee.Visible = true; 
       tabcontent3.Style.Add("height", "80%"); 
       //ViewState["dt_alotee_view"] = dt_alotee_data; 
       btn_save_alotee.Enabled = false; 
       // Response.Redirect(Request.Url.AbsoluteUri); 
      } 
      else 
      { 
       lbl_error_3.Text = "Unable to add Allottee Information"; 
      } 
     } 
+0

* resposnse.redirect在这种情况下不是解决方案*为什么? – 2014-10-26 14:38:16

+0

,因为它移动到第一个标签..但我希望它留在当前标签..即时通讯在同一页上使用多个标签(标签由单选按钮控制) – 2014-10-26 14:40:35

+0

在InserAllotee方法中添加一个重复的检查逻辑。 – 2014-10-26 14:42:18

回答

1

你的问题似乎表明一个按钮事件处理程序触发页面刷新 - 这是奇怪的。页面刷新导致GET操作。尽管如此,服务器端数据的更改只能在POST请求中完成。而按钮事件处理程序应该只在单击按钮时调用。我无法从这些代码中得知您的架构违反了这些规定。

+0

我调试代码时刷新页面它不去btn_save_click()但记录插入db重复 – 2014-10-26 15:15:43

+0

如果它不去这个函数,记录不是从此功能插入(或不在该时间点)。除了您发布的代码之外,还有其他插入代码吗? – 2014-10-26 15:16:59

+0

我确定没有 – 2014-10-26 15:47:55