C# 输入字符串的格式不正确(正在将字符串转换为十进制)

C# 输入字符串的格式不正确(正在将字符串转换为十进制),c#,asp.net,string,input,decimal,C#,Asp.net,String,Input,Decimal,我正在尝试转换*.aspx页面中的字符串: 标点: function updateOnClick() { if (!toIgnore) { refNo = document.getElementById("txtRef").value; note1000 = removeCommas(document.getElementById("txtNote_1000").value.substring(1)); n

我正在尝试转换*.aspx页面中的字符串:

标点:

function updateOnClick() {

        if (!toIgnore) {
            refNo = document.getElementById("txtRef").value;
            note1000 = removeCommas(document.getElementById("txtNote_1000").value.substring(1));
            note100 = removeCommas(document.getElementById("txtNote_100").value.substring(1));
            note50 = removeCommas(document.getElementById("txtNote_50").value.substring(1));
            note20 = removeCommas(document.getElementById("txtNote_20").value.substring(1));
            note10 = removeCommas(document.getElementById("txtNote_10").value.substring(1));
            note5 = removeCommas(document.getElementById("txtNote_5").value.substring(1));
            note2 = removeCommas(document.getElementById("txtNote_2").value.substring(1));
            note1 = removeCommas(document.getElementById("txtNote_1").value.substring(1));
            coins = removeCommas(document.getElementById("txtCoins").value.substring(1));
            cheque = removeCommas(document.getElementById("txtCheque").value.substring(1));
            outstanding = removeCommas(document.getElementById("txtOutstanding").value.substring(1));
            total = removeCommas(document.getElementById("txtTotal").value.substring(1));
            collectable = removeCommas(document.getElementById("txtCollectable").value.substring(1));
            difference = removeCommas(document.getElementById("txtDifference").value.substring(1));
            collectionDate = document.getElementById(prefix + "txtDate").value;

            iniXmlHttp();

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    responseText = xmlhttp.responseText;

                    if (responseText == "") {
                        loadDailyCollectionTable();
                        document.getElementById("txtRef").focus();
                        document.getElementById("txtRef").select();
                    }

                }
            }

            xmlhttp.open("GET", "DailyCollectionPage.aspx?funcName=updateDailyCollection&RefNo=" + refNo +
            "&collectionDate=" + collectionDate + "&note1000=" + note1000 + "&note100=" + note100 +
            "&note50=" + note50 + "&note20=" + note20 + "&note10=" + note10 + "&note5=" + note5 +
            "&note2=" + note2 + "&note1=" + note1 + "&coins=" + coins + "&cheque=" + cheque +
            "&outstanding=" + outstanding + "&total=" + total + "&collectable=" + collectable + 
            "&difference=" + difference, true);

            xmlhttp.send();
        }
        else
            toIgnore = false;
    }
在代码隐藏中,当我尝试将字符串转换为十进制时,我在这一行中遇到错误:

dailyCollection.Notes_1000 = Convert.ToDecimal(Request["note1000"]);
错误是:
输入字符串的格式不正确。


有人能告诉我我的代码出了什么问题吗。任何帮助都将不胜感激

你试过这样做吗?-

dailyCollection.Notes_1000 = Convert.ToDecimal(Request["note1000"].ToString());
此外,您还应该使用,它将处理此类错误情况

例如:


输入字符串的格式不正确。
您确定您的代码总是返回
它从不返回
空值
? 我认为当您的字符串为
Null
Empty
时,您会收到此错误,请尝试先检查Null或空值

  if(!string.IsNullOrEmpty(Convert.Tostring(Request["note1000"]))) 
{
   dailyCollection.Notes_1000 = Convert.ToDecimal(Request["note1000"].ToString());

您是否尝试通过简单地将请求[“note1000”]转换为字符串来检查得到的内容?可能您得到的值不是十进制值,或者可能您得到的值类似于附加了十进制值的垃圾字符。首先检查您得到的值。然后,您可以决定下一步该
removecomas
似乎是罪魁祸首,也可以发布
note1000
请求[“note1000”]中的值是多少?@v4仇杀,好家伙!我使用该函数删除逗号、美元符号和其他字符,并将值作为十进制数传递。如果用户输入100并按enter键,文本框将显示$100.00。因此
removeCommas()
函数将删除这些字符并返回十进制值。但是,如果用户输入100并直接单击更新按钮,则该函数将无法删除任何内容,并将错误作为错误的输入格式返回。谢谢你指出我的问题。+1谢谢你的回答。但给我带来问题的错误是因为我在脚本中使用了JavaScript函数removeCommas。
  if(!string.IsNullOrEmpty(Convert.Tostring(Request["note1000"]))) 
{
   dailyCollection.Notes_1000 = Convert.ToDecimal(Request["note1000"].ToString());