I have the following call to 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 is bool which would be false in this case. The javascript is as follows:
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);
}
When I hard code this._SortByDescription as 'false' in the javascript call, it works. But replacing 'false' with this._SortByDescription results in error. Also I observed while debugging that the javascript receives the value of this._SortByDescription as 'False' instead of 'false'. Not sure if this matters. I am working on javascript for the first time. Please help.
Try converting to lower case:
this._SortByDescription.ToLower();
If the property of type bool
:
this._SortByDescription.ToString().ToLower();
You could also define "True" and "False" in the beginning of your function/JS. It may seem tedious, but it worked for me.
function xxx {
var True = true;
var False = false;
// code...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With