簡體   English   中英

格式異常未由C#中的用戶代碼處理

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

錯誤消息不斷彈出。 另外,當我運行代碼時,似乎根本無法正常工作。 我正在嘗試將數據傳遞到另一個頁面。 有什么建議嗎? 這是主頁代碼,

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

很難知道沒有堆棧跟蹤的確切問題是什么。 但是,基於谷歌搜索“用戶代碼未處理格式異常”,很可能是decimal.Parse(totalRevenue); 陳述是問題所在。 由於totalRevenue的字符串值是從totalRateLabel.Text設置的, totalRateLabel.Text如果該標簽具有特殊字符(如美元符號)需要首先刪除,我不會感到驚訝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM