0

错误消息不断弹出。另外,当我运行代码时,它似乎根本不起作用。我正在尝试将数据传递到另一个页面。有什么建议吗?这是主页代码,

public partial class _Default : System.Web.UI.Page
{
static int numBeachBookingInt = 0;
static int numBushBookingInt = 0;
static decimal totRevenue = 0;

protected void Page_Load(object sender, EventArgs e)
{
    string totalRevenue;
    if (Convert.ToString(Session["confirmBooking"]) == "confirm" && Convert.ToString(Session["bachType"]) == "bush")
    {
        totalRevenue = (string)(Session["totalRevenue"]);
        totRevenue += decimal.Parse(totalRevenue);
        totRevenueLabel.Text = String.Format("{0:c}", totRevenue);
        numBushBooking += 1;
        numBushHouseLabel.Text = numBushBooking.ToString();
        Session["confirmBooking"] = "no current booking";
        Session["bachType"] = "none";
    }
    else if (Convert.ToString(Session["confirmBooking"]) == "confirm" && Convert.ToString(Session["bachType"]) == "beach")
    {
        totalRevenue = (string)(Session["totalRevenue"]);
        totRevenue += decimal.Parse(totalRevenue);
        totRevenueLabel.Text = String.Format("{0:c}", totRevenue);
        numBeachBooking += 1;
        numBeachHouseLabel.Text = numBeachBooking.ToString();
        Session["confirmBooking"] = "no current booking";
        Session["bachType"] = "none";
    }
    numBeachHouseLabel.Text = numBeachBooking.ToString();
    numBushHouseLabel.Text = numBushBooking.ToString();

这是第二个。

protected void confirmButton_Click(object sender, EventArgs e)
{
    Session["confirmBooking"] = "confirm";
    Session["totalRevenue"] = totalRateLabel.Text;
    switch (bachTypeRadioButtonList.Text)
    {
        case "Beach":
            Session["bachType"] = "beach";
            break;
        case "Bush":
            Session["bachType"] = "bush";
            break;
        default:
            Session["bachType"] = "none";
            break;
    }
    Response.Redirect("MainBookingForm.aspx");
}
4

1 回答 1

0

如果没有堆栈跟踪,很难知道您的确切问题是什么。但是,根据谷歌搜索“用户代码未处理格式异常”,很可能其中一个decimal.Parse(totalRevenue);语句是问题所在。由于 的字符串值totalRevenue是从 设置的totalRateLabel.Text,因此如果该标签包含您需要首先删除的特殊字符(如美元符号),我不会感到惊讶。

于 2013-09-07T06:50:45.783 回答