【发布时间】:2014-10-14 19:49:53
【问题描述】:
我正在开发一个存在问题的应用程序。当我点击提交按钮时,数据被插入到数据库中。但是当我按下 ctrl+R 或 f5 时,会出现一个 chrome 或 IE 弹出窗口,上面写着 Confirm Form Resubmission。当我点击继续时,记录被复制到数据库中。
我的问题是,
为什么会出现这个弹出窗口?因为回发?如果因为回发,那么我的代码是否有任何问题,或者在回发时每个人都会发生。
使用 mvc 会彻底解决这个问题吗?
我的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
paramArray = new string[9];
paramValues = new object[9];
try
{
paramArray[0] = "@AccountNumber";
paramValues[0] = (!string.IsNullOrEmpty(this.txtAccountNumber.Value) ? this.txtAccountNumber.Value.Trim() : string.Empty);
paramArray[1] = "@OpeningBalance";
paramValues[1] = (!string.IsNullOrEmpty(this.txtOpeningBalance.Value) ? Convert.ToDouble(this.txtOpeningBalance.Value.Trim()) : 0.00);
paramArray[2] = "@ClosingBalance";
paramValues[2] = (!string.IsNullOrEmpty(this.txtClosingBalance.Value) ? Convert.ToDouble(this.txtClosingBalance.Value.Trim()) : 0.00);
paramArray[3] = "@PaymentMode";
paramValues[3] = this.ddlModeofPayment.Value;
paramArray[4] = "@PaymentDate";
paramValues[4] = this.dtPaymentDate.Value;
paramArray[5] = "@PaymentAmount";
paramValues[5] = (!string.IsNullOrEmpty(this.txtPaymentAmount.Value) ? Convert.ToDouble(this.txtPaymentAmount.Value.Trim()) : 0.00);
paramArray[6] = "@isAccount";
paramValues[6] = true;
paramArray[7] = "@UserId";
paramValues[7] = (!string.IsNullOrEmpty(this.User.Identity.Name.Remove(0, 7)) ? this.User.Identity.Name.Remove(0, 7) : string.Empty);
paramArray[8] = "@isProcessed";
paramValues[8] = default(bool);
var success = herlperUtility.ExecuteParameterizedQuery("{CALL asp_sp_InsertPayment(?,?,?,?,?,?,?,?,?)}", paramArray, paramValues);
if (!string.IsNullOrEmpty(success.Rows[0]["ReferenceNumber"].ToString()))
{
this.Page.Response.Redirect("AccountPaymentScreen.aspx?flag=1");
divSuccess.Attributes.Add("style", "display:block");
this.refId.InnerText = "<b>Success!</b> The " + success.Rows[0]["ReferenceNumber"] + " has been successfuly forwarded to the supervisor";
this.ClearFields();
}
else
{
this.divFailure.Attributes.Add("style", "display:block");
}
}
catch (Exception ex)
{
this.divFailure.Attributes.Add("style", "display:block");
this.divFailure.InnerText = ex.Message;
}
}
【问题讨论】:
-
1.是的,第 2 部分。可能,mvc 也比普通的 asp 更有助于数据处理(在我看来,它也更容易编辑)