c# - Uncaught ReferenceError :False is not defined

标签 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。请帮忙。

最佳答案

尝试转换为小写:

this._SortByDescription.ToLower();

如果bool类型的属性:

this._SortByDescription.ToString().ToLower();

关于c# - Uncaught ReferenceError :False is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20664000/

相关文章:

asp.net - 为什么我的 ASP.NET MVC 持久身份验证 cookie 不起作用?

c# - 动态委托(delegate)在 C# 中将方法作为参数传递

c# - ObservableCollection 优于 ObjectSet

javascript - 为什么原型(prototype)函数比默认声明的函数慢 40 倍?

javascript - 在 Angular 服务中重用/重构代码

c# - ASP.NET GridView - 控件在内容页面中移动

c# - 无法将类型 System.Data.Entity.Core.Objects.ObjectResult 隐式转换为 System.Data.Objects.ObjectResult

c# - 使用自定义类型填充数据表列

javascript - 如何从 .getCurrentPosition() 函数 javascript 访问变量

javascript - CORS 阻止访问 XMLHttpRequest