Unexpected behavior such as a button click event being called twice in an ASP.NET application, particularly when it's observed only in IIS and not during code debugging,
What I have tried:
I am using loading bar on any button click with the help of below javascript code.
<script type="text/javascript" src="scripts/loadbar/jquery.min.js"></script>
<script type="text/javascript">
var IsExportClick = false;
function HideProgressBar() {
debugger;
IsExportClick = true;
}
function ShowProgress() {
if (!IsExportClick) {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left});
}, 200);
}
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
this are my frontend html code of button
<tr>
<td colspan="5" align="center">
<asp:Button runat="server" ID="btnSave" Text="Save" CssClass="btn btn-primary" OnClientClick="return validate();" Width="150px" Visible="false" OnClick="btnSave_Click" />
<asp:Button runat="server" ID="btnTransaction" Text="Process" CssClass="btn btn-primary" OnClientClick="return validate();" Width="150px" Visible="false" OnClick="btnTransaction_Click" />
<asp:Button runat="server" ID="btnProcessOffline" Text="Process Offline" CssClass="btn btn-primary" OnClientClick="return validate();" Width="150px" Visible="false" OnClick="btnProcessOffline_Click" />
<asp:HiddenField runat="server" ID="btnPayment_ClickData" /></td> </tr>
this are my button click event which call twice after few transaction happened.
1 protected void btnTransaction_Click(object sender, EventArgs e)
2 {
3
4 lblRecords.Text = string.Empty;
5 DGO_OnlineApps = (OnlineAppsHandler)Session["Session1"];
6 DataTable dtExistData = new DataTable();
7
8 dtExistData = (DataTable)ViewState["ViewState1"];
9 int chkCnt = 0;
10 int processRecordCnt = 0;
11 int failedRecordCnt = 0;
12 Random rnd = new Random();
13 int batchRandomNo = rnd.Next(100, 999);
14 batchRandomNo = batchRandomNo + Convert.ToInt32(DateTime.Now.ToString("ddMMyyyy"));
15 string batchno = GenerateBatchNo();
16 foreach (DataGridItem item in dgCCTransaction.Items)
17 {
18 CheckBox chkSelect = (CheckBox)item.FindControl("chkSelect");
19 if (chkSelect != null)
20 {
21 if (chkSelect.Checked && dtExistData.AsEnumerable().Where(x => x.Field<Int64>("ChkNo").ToString() == item.Cells[13].Text && x.Field<string>("Status") != "Done").Count() > 0)
22 {
23 chkCnt++;
24 DataTable data = new DataTable();
25 data = Method1(Convert.ToInt32(item.Cells[5].Text), item.Cells[6].Text,"01" + " " + item.Cells[7].Text, item.Cells[8].Text);
26 DataTable dtGetDetails = new DataTable();
27 dtGetDetails = GetDetails(Convert.ToInt32(item.Cells[5].Text));
28 if (data != null && data.Rows.Count > 0)
29 {
30 if (data != null && !string.IsNullOrEmpty(data.Rows[0]["ResponseCode"].ToString()) && !string.IsNullOrEmpty(data.Rows[0]["ApprovalCode"].ToString()) && !data.Rows[0]["ResponseCode"].ToString().Contains("FAILED"))
31 {
32 string recid = InsertMemCCTrans("Done",Convert.ToInt32(item.Cells[5].Text), item.Cells[1].Text, "01" + " " + item.Cells[7].Text, data,item.Cells[12].Text, item.Cells[8].Text,batchRandomNo, batchno);
33 SendEmail("CCAuthSuccess", item.Cells[5].Text, item.Cells[7].Text, item.Cells[8].Text, "");
34 foreach (DataRow row in dtExistData.Rows)
35 {
36 if (row["ChkNo"].ToString() == item.Cells[13].Text)
37 {
38 row["TranStatus"] = "Done";
39 row["RECID"] = recid;
40 processRecordCnt++;
41 }
42
43 }
44 }
45 else
46 {
47 string recid = InsertMemCCTrans("Transaction Failed", Convert.ToInt32(item.Cells[5].Text), item.Cells[1].Text, "01" + " " + item.Cells[7].Text, data, item.Cells[12].Text, item.Cells[8].Text, batchRandomNo, null);
48 SendEmail("CCAuthUnSuccess", item.Cells[5].Text, item.Cells[7].Text, item.Cells[8].Text, dtGetDetails.Rows[0]["MP"].ToString());
49 foreach (DataRow row in dtExistData.Rows)
50 {
51 if (row["ChkNo"].ToString() == item.Cells[13].Text)
52 {
53 row["TranStatus"] = "Transaction Failed";
54 row["RECID"] = recid;
55 failedRecordCnt++;
56 }
57
58 }
59 }
60 }
61 else
62 {
63 string recid = InsertMemCCTrans("Transaction Failed", Convert.ToInt32(item.Cells[5].Text), item.Cells[1].Text, "01" + " " + item.Cells[7].Text, data, item.Cells[12].Text, item.Cells[8].Text, batchRandomNo, null);
64 SendEmail("CCAuthUnSuccess", item.Cells[5].Text, item.Cells[7].Text, item.Cells[8].Text, dtGetDetails.Rows[0]["MP"].ToString());
65 foreach (DataRow row in dtExistData.Rows)
66 {
67 if (row["ChkNo"].ToString() == item.Cells[13].Text)
68 {
69 row["TranStatus"] = "Transaction Failed";
70 row["RECID"] = recid;
71 failedRecordCnt++;
72 }
73
74 }
75 }
76 }
77 }
78 }
79
80 if (dtExistData != null)
81 {
82 if (dtExistData.Rows.Count > 0)
83 {
84 dgCCTransaction.DataSource = dtExistData;
85 dgCCTransaction.DataBind();
86 lblRecords.Text = chkCnt + " out of " + dtExistData.Rows.Count + " processed." +
87 "<br />Total Successful Transaction - " + processRecordCnt + "/" + chkCnt +
88 "<br />Total Failed Transaction - " + failedRecordCnt + "/" + chkCnt;
89
90
91
92
93 }
94 }
95 else
96 {
97 LoadPaymentData();
98 }
99 }