C# 未捕获引用错误:未定义False
我对javascript有以下调用: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
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
!=这个。_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...
}