未捕获的引用错误:未定义False

R B*_*R B 3 javascript c# asp.net

我有以下对javascript的调用:

protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        this._BtAdd.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + sourceListId + ",  " + destListId + ",  " + selectedValuesId + ", false, true, "+ this._SortByDescription +");");
        this._BtRemove.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + destListId + ",  " + sourceListId + ",  " + selectedValuesId + ", false, false, " + this._SortByDescription + ");");

        if (!this._PostBackOnAll)
        {
            this._BtAddAll.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + sourceListId + ",  " + destListId + ",  " + selectedValuesId + ", true, true, " + this._SortByDescription + " );");
            this._BtRemoveAll.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + destListId + ",  " + sourceListId + ",  " + selectedValuesId + ", true, false, " + this._SortByDescription + " );");
        }

        // Check if user can double-click on listbox item to move it
        if (this._AllowDblClick)
        {
            this._LstSource.Attributes.Add("ondblclick", "GXDualListBox_MoveDualList(" + sourceListId + ",  " + destListId + ",  " + selectedValuesId + ", false, true, " + this._SortByDescription + " );");
            this._LstDestination.Attributes.Add("ondblclick", "GXDualListBox_MoveDualList(" + destListId + ",  " + sourceListId + ",  " + selectedValuesId + ", false, false, " + this._SortByDescription + " );");
        }
    }
Run Code Online (Sandbox Code Playgroud)

this._SortByDescription是bool,在这种情况下是假的.javascript如下:

function GXDualListBox_MoveDualList(srcList, destList, selectedValues, moveAll, isAdd,sortByDescription) 
{

if ((srcList.selectedIndex == -1) && (moveAll == false)) {
    return;
}
newDestList = new Array(destList.options.length);

for (var len = 0; len < destList.options.length; len++) {
    if (destList.options[len] != null) {
        newDestList[len] = new Option(destList.options[len].text, destList.options[len].value, destList.options[len].defaultSelected, destList.options[len].selected);
    }
}
for (var i = 0; i < srcList.options.length; i++) {
    if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) {
            newDestList[len] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected);
            len++;
    }
}

if (sortByDescription) {
    newDestList.sort(GXDualListManager_CompareOptionValues);   
    newDestList.sort(GXDualListManager_CompareOptionText);  
}


for (var j = 0; j < newDestList.length; j++) {
    if (newDestList[j] != null) {
        destList.options[j] = newDestList[j];
    }
}   
}

if (isAdd)
    buildSelectedList(destList, selectedValues);
else
    buildSelectedList(srcList, selectedValues);
} 
Run Code Online (Sandbox Code Playgroud)

当我在javascript调用中将this._SortByDescription硬编码为'false'时,它可以工作.但用this._SortByDescription替换'false'会导致错误.此外,我在调试时观察到javascript接收this._SortByDescription的值为'False'而不是'false'.不确定这是否重要.我是第一次使用javascript.请帮忙.

Don*_*own 13

尝试转换为小写:

this._SortByDescription.ToLower();
Run Code Online (Sandbox Code Playgroud)

  • @taco是的,它区分大小写,以及JavaScript上的所有内容.在浏览器的开发工具控制台上自己尝试一下.输入"TRUE","True"和"true".你会看到只有最后一个是好的.它与PHP有点不同. (2认同)
  • 应该不是this._SortByDescription.ToString()。ToLower();`吗?我得到'bool'不包含'ToLower'的定义,也找不到找不到接受类型为'bool'的第一个参数的扩展方法'ToLower'(是否缺少using指令或程序集引用?)。即使将其括在字符串`“ send(a,b,” + this._SortByDescription.ToLower()+“,d)”`中,也是如此。 (2认同)