Welcome Guest Search | Active Topics | Sign In | Register

EO listbox - Init via a separate Window failed Options
PRO POTSDAM GmbH
Posted: Monday, March 4, 2024 6:33:00 AM
Rank: Advanced Member
Groups: Member

Joined: 6/17/2010
Posts: 35
I have a separate window (urlaub.aspx), that is called via a button from an intranet application.

Via CodeBehind (urlaub.aspx.cs) an EO listbox is filled via SQL script when loading.

After loading, the javascript initForm() is executed.

There, a passed string in the listbox is to be searched for using the function ListboxPruefen() and, if found, marked accordingly.

When executing the function, I receive the error message "ListboxPruefen(): TypeError: Cannot read properties of undefined (reading '0')"

It appears that the control is not yet loaded or available at loadtime.

In contrast, the listBox1selected function correctly recognizes and passes a selected entry.

What can I do?



<%@ Page Inherits="urlaub" Language="c#" CodeFile="urlaub.aspx.cs" AutoEventWireup="true" %>
<%@ Register TagPrefix="eo" Assembly="EO.Web" Namespace="EO.Web" %>
<!DOCTYPE html>
<html lang="de">
<meta charset="utf-8">
<head id="Head1" runat="server">
<link rel="stylesheet" href="../App_Themes/posProtokoll.css" type="text/css" />
<script src="../App_Themes/urlaub.js"></script>
</head>
<body>
<form id="form1" runat="server">
<body onload="initForm();" >
<div id="DivAdrX" style="position:absolute;left:0px;top:0px;height:275px;width:350px;padding:10;z-index:0;" class="hintergrund" >
<eo:ListBox id="ListBox1" ControlSkinID="None" Height="150px" Width="250px" onclick="listBox1selected();" runat="server" >
<BodyStyle CssText="border:solid 1px #868686;background-color:white;" />
<ItemListStyle CssText="padding: 1px;" />
<ItemStyle CssText="font-family:Tahoma;font-size:9pt;font-weight:solid;" />
<ListBoxStyle CssText="font-family:Tahoma; font-size:11px;" />
<SelectedItemStyle CssText="color:#FFFFFF;background-color:#4682B4;background-repeat:repeat;border:solid 1px;font-family:Tahoma;font-size:9pt;font-weight:solid;" />
<ItemHoverStyle CssText="color:#FFFFFF;background-color:#4682B4;background-repeat:repeat;border:solid 1px;font-family:Tahoma;font-size:9pt;font-weight:solid;" />
</eo:ListBox>
</div>
<input type="button" id="Button1" class="cbutton2" style="position:absolute;left:30px;top:225px;height:20px;width:100px;color:blue" value="OK" onclick="Button1pressed();" />
<input type="button" id="Button2" class="cbutton2" style="position:absolute;left:140px;top:225px;height:20px;width:100px;color:blue" value="ESC" onclick="Button2pressed();" />
</div>
</body>
</form>
</html>


function initForm() {

try
{
_uebernahme=sessionStorage.getItem("grund");

if (_uebernahme!='' && _uebernahme!='0' && _uebernahme!=null && _uebernahme!=undefined) {

setTimeout(function() {
ListboxPruefen(_uebernahme);
}, 100);
}
}
catch (err)
{
alert('initForm(): ' + err.toString());
}
}


function ListboxPruefen(_katalogEintrag) {

//protokoll('ListboxPruefen()');

try
{

var _gefunden=0;
var oListBox1 = eo_GetObject("ListBox1");

for(var i=0; i < oListBox1.length; i++){

if(oListBox1.options[i].value == _katalogEintrag) {
oListBox1.options[i].selected = true;
break;
}
}

if (_gefunden==0) {
oListBox1.options[0].selected = true; //(ohne)
}

}
catch (err)
{
alert('ListboxPruefen(): ' + err.toString());
}
}



function listBox1selected(_this) {

try
{

var oListBox1 = eo_GetObject("ListBox1");
_uebergabeDaten=oListBox1.getSelectedItem().getText();

if (_uebergabeDaten!='' && _uebergabeDaten!=_uebernahme && _uebergabeDaten!='(ohne)') {
setColorEnable(oButton1); //OK
} else {
setColorDisable(oButton1); //Not OK
}

}
catch (err)
{
alert('listBox1selected(): ' + err.toString());
}
}



eo_support
Posted: Monday, March 4, 2024 10:10:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

eo_GetObject returns a JavaScript object. It only supports methods listed here:

https://www.essentialobjects.com/doc/jsdoc.public.web.listbox.html

This is NOT the same as the HTMl "select" DOM object. The following code you use is wrong because options is a property of the "select" DOM object.

Code: JavaScript
oListBox1.options[i]


In fact our ListBox implementation does not use HTML select object at all. So you must use our documented API to access the list items. For example, the following code in your code is correct:

Code: JavaScript
var oListBox1 = eo_GetObject("ListBox1");
_uebergabeDaten=oListBox1.getSelectedItem().getText();


This is because it uses getSelectedItem, which is a documented method of the ListBox object.

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!


PRO POTSDAM GmbH
Posted: Tuesday, March 5, 2024 6:00:20 AM
Rank: Advanced Member
Groups: Member

Joined: 6/17/2010
Posts: 35
This has worked for me:

var _katalogItem='Test';
var _found=0;
var oListBox1 = eo_GetObject("ListBox1");
var _intLaenge = oListBox1.getItemCount();
for(var i=0; i < _intLaenge; i++){
var _strTest = oListBox1.getItem(i).getText();
if (_strTest != '') {
if(_strTest == _katalogItem) {
var item = oListBox1.getItem(i);
oListBox1.setSelectedItem(item);
_found=1;
break;
}
}
}
if (_found==0) {
var item = oListBox1.getItem(0);
oListBox1.setSelectedItem(item);
}



Thanks.
eo_support
Posted: Tuesday, March 5, 2024 10:34:44 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Great!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.