就像标题所说我试图确保在执行第二个按钮之前单击一个按钮。这就是我所拥有的,现在我相信calculateButtonWasClicked = true;超出第二个按钮范围,因此它总是评估为false。有一个更好的方法吗?提前谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows;
namespace priceQuote
{
public partial class Default : System.Web.UI.Page
{
//Declaring Variable
public bool calculateButtonWasClicked = false;
protected void Page_Load(object sender, EventArgs e)
{
//Disabling the unobtrusive data validation
UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
}
protected void calculateButton_Click(object sender, EventArgs e)
{
//Declaring Variables
decimal salesPrice;
decimal discountPercent;
//Attempting to convert user input into decimal data types
decimal.TryParse(salesPriceBox.Text, out salesPrice);
decimal.TryParse(discountBox.Text, out discountPercent);
//Calculating discount amount and assigning the value to a label
decimal discountAmount = salesPrice * (discountPercent * .01m);
discountAmountLabel.Text = discountAmount.ToString("c");
//Calculating total amount and assigning the value to a label
decimal total = salesPrice - discountAmount;
totalLabel.Text = total.ToString("c");
//Changing variable from false to true
calculateButtonWasClicked = true;
}
protected void confirmButton_Click(object sender, EventArgs e)
{
if (calculateButtonWasClicked)
{
Session["salesPrice"] = salesPriceBox.Text;
Session["discountAmount"] = discountAmountLabel.Text;
Session["total"] = totalLabel.Text;
//Redirecting to new page
Response.Redirect("~/confirmation.aspx");
}
else
{
calculateWarningLabel.Text = "Amounts need to be calculated first. Please click calculate button.";
}
}
}
}