Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未捕获引用错误:未定义False_C#_Javascript_Asp.net - Fatal编程技术网

C# 未捕获引用错误:未定义False

C# 未捕获引用错误:未定义False,c#,javascript,asp.net,C#,Javascript,Asp.net,我对javascript有以下调用: protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); this._BtAdd.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + sourceListId + ", " + destListId + ", " + selectedValuesId + ", fa

我对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 + " );");
        }
    }
此.\u SortByDescription是bool,在本例中为false。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);
} 
函数GXDualListBox\u MoveDualList(srcList、destList、selectedValues、moveAll、isAdd、sortByDescription)
{
if((srcList.selectedIndex=-1)和&(moveAll==false)){
返回;
}
newDestList=新数组(destList.options.length);
对于(变量len=0;len
当我在javascript调用中将这个硬编码为'false'时,它就工作了。但将“false”替换为此。\ u SortByDescription将导致错误。调试时,我还观察到javascript接收到此值。\ u SortByDescription为'False'而不是'False'。不知道这是否重要。
我第一次使用javascript。请帮忙

尝试转换为小写:

this._SortByDescription.ToLower();
如果类型为
bool
的属性:

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

如前所述,在
c#
的土地上它是
False
,但在
javascript
中它是
False
。您只需重新调整代码,使其返回LC版本

this._SortByDescription ? "true" : "false"
我面临着类似的情况。我的ASP页面中有Scriptlet,但由于相同的原因失败:

isSubSpeciesAspect = <%=Model.aspect.ToLower() === "subspecies"%>;
我只是需要移动一些东西来解决这个问题:

isSubSpeciesAspect = ("<%=Model.aspect.ToLower()%>" === "subspecies");
issubspeciespect=(“”=“亚种”);
您还可以在函数/JS的开头定义“True”和“False”。这可能看起来很乏味,但对我来说很有效

function xxx {
    var True = true;
    var False = false;

    // code...
}

是的,这是因为
false
!=False
。你试过改变它吗?“修好它,然后你就可以走了。”多谢你的回复。我正在将_SortByDescription的值设置为“false”。当调用javascript时,我可以看到它发送的是'false'而不是'false'。嗯,这不是您的错误消息所说的。您在生成的源代码上看到了什么?@DontVoteMeDown生成的源代码是:“GXDualListBox_MoveDualList(……,true,true,False);”我为格式错误道歉。但是在代码中我可以看到它的值。_SortByDescription设置为'false',但是javascript以某种方式接收到它为'false',那么我们来试试
这个。_SortByDescription.ToLowerCase()
?在javascript中,true和false需要小写吗?我刚才得到了同样的结果,但是,uncaughtreferenceerror:TRUE没有定义。我已经习惯了用PHP将它们大写。@taco是的,它区分大小写,JavaScript上的所有内容也是如此。自己在浏览器的开发工具控制台上尝试。键入
TRUE
TRUE
TRUE
。你会发现只有最后一个是可以的。它与PHP有点不同。它不应该是
this.\u SortByDescription.ToString().ToLower()?I get
“bool”不包含“ToLower”的定义,并且找不到接受“bool”类型的第一个参数的扩展方法“ToLower”(是否缺少using指令或程序集引用?
否则。即使它包含在字符串中,
“sending(a,b,“+this.\u SortByDescription.ToLower()+”,d)”
,就像这样。来这里也是为了说同样的话。ToLower()仅适用于字符串(因此,除非我遗漏了某些内容,否则应编辑已批准的答案)。
function xxx {
    var True = true;
    var False = false;

    // code...
}