简体   繁体   English

格式异常未由C#中的用户代码处理

[英]format exception was unhandled by user code in c#

The error message keeps popping up. 错误消息不断弹出。 Also, when I running the codes, it seems it's not working at all. 另外,当我运行代码时,似乎根本无法正常工作。 I'm trying passing data to another page. 我正在尝试将数据传递到另一个页面。 Any suggestion? 有什么建议吗? This is the main page code, 这是主页代码,

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();

this is the second. 这是第二个。

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");
}

It's hard to know what you're exact problem is without a stack trace. 很难知道没有堆栈跟踪的确切问题是什么。 However, based on Googling "Format exception was unhandeled by user code", it's likely that one of the decimal.Parse(totalRevenue); 但是,基于谷歌搜索“用户代码未处理格式异常”,很可能是decimal.Parse(totalRevenue); statements is the problem. 陈述是问题所在。 Since the string value of totalRevenue is set from totalRateLabel.Text , I wouldn't be surprised if that label has special characters (like a dollar sign) that you need to remove first. 由于totalRevenue的字符串值是从totalRateLabel.Text设置的, totalRateLabel.Text如果该标签具有特殊字符(如美元符号)需要首先删除,我不会感到惊讶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM