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

时间:2013-12-18 16:57:15

标签: c# javascript 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 + " );");
        }
    }

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

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

3 个答案:

答案 0 :(得分:13)

尝试转换为小写:

this._SortByDescription.ToLower();

答案 1 :(得分:0)

正如所讨论的那样,False的土地为c#falsejavascript。您只需重新编写代码,以便返回LC版本。

this._SortByDescription ? "true" : "false"

我面对类似的事情。我的ASP页面中有scriptlet,但出于同样的原因失败了:

isSubSpeciesAspect = <%=Model.aspect.ToLower() === "subspecies"%>;

在生成的JS中,它出现为:

isSubSpeciesAspect = True;

我只需要搬家来解决这个问题:

isSubSpeciesAspect = ("<%=Model.aspect.ToLower()%>" === "subspecies");

答案 2 :(得分:0)

您还可以在函数/ JS的开头定义“ True”和“ False”。这似乎很乏味,但对我有用。

yargs