Ticket T293500
Visible to All Users

ASPxComboBox - "Object doesn't support property or method" error occurs when the GetSelectedItem method is used

created 10 years ago

Hi,

I have some javascript that constructs the clientside name of a combobox and then tries to get the selected text from the combobox . Trouble is it's throwing an error 'Object doesn't support property or Method GetSelectedItem.

[Javascript]

JavaScript
var previousMemo; var newMemo; var setScore; var newScore; var setScore2; var newScore2; var setScore3; var newScore3; function SaveComments(sectionName) { newMemo = "mem" + sectionName + "Comments";; previousMemo = "memPrevious" + sectionName + "Comments"; setScore = "lbl" + sectionName + "Score"; newScore = "cmb" + sectionName + "Score"; customCallbackParameter = sectionName; SaveCommentsCallback.PerformCallback(customCallbackParameter); } function SaveCommentsEndCallback(s, e) { var resultstring = e.result; var newMemoBoxControl = ASPxClientControl.GetControlCollection().GetByName(newMemo); newMemoBoxControl.SetText(""); var prevMemoBoxControl = ASPxClientControl.GetControlCollection().GetByName(previousMemo); var splitResult = resultstring.split("|"); prevMemoBoxControl.SetText(splitResult[1]); prevMemoBoxControl.SetHeight(splitResult[0]); setScore.SetText(newScore.GetSelectedItem().text); newScore.SetSelectedIndex(-1); }

[ASPx]

ASPx
<dx:ASPxFormLayout ID="frmProjectDetailsScore" runat="server" ColCount="2" Width="100%" Height="100%"> <Items> <dx:LayoutGroup ColCount="2" ColSpan="2" Width="98%" Caption="Score and Comments"> <Items> <dx:LayoutItem ShowCaption="False"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxLabel ID="ASPxFormLayout1_E1" runat="server" Text="Score" Visible="false"> </dx:ASPxLabel> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> </dx:LayoutItem> <dx:LayoutItem ShowCaption="true" Caption="Score Section" ColSpan="2"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxComboBox ID="cmbProjectDetailsScore" ClientInstanceName="spnProjectDetailsScore" runat="server" ClientEnabled="false" EnableClientSideAPI="true"> <Items> <dx:ListEditItem Text="0" Value="0" /> <dx:ListEditItem Text="1" Value="1" /> <dx:ListEditItem Text="2" Value="2" /> <dx:ListEditItem Text="3" Value="3" /> <dx:ListEditItem Text="4" Value="4" /> <dx:ListEditItem Text="5" Value="5" /> <dx:ListEditItem Text="6" Value="6" /> <dx:ListEditItem Text="7" Value="7" /> <dx:ListEditItem Text="8" Value="8" /> <dx:ListEditItem Text="9" Value="9" /> <dx:ListEditItem Text="10" Value="10" /> </Items> </dx:ASPxComboBox> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> </dx:LayoutItem> <dx:LayoutItem ShowCaption="true" Caption="Current" ColSpan="2"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxLabel ID="lblProjectDetailsScore" runat="server" ClientInstanceName="lblProjectDetailsScore" /> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> </dx:LayoutItem> <dx:LayoutItem Caption="Comment" ColSpan="2" VerticalAlign="Top"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxMemo ID="memProjectDetailsComments" ClientInstanceName="memProjectDetailsComments" runat="server" Height="110px" Width="98%"> <Border BorderStyle="Solid" /> </dx:ASPxMemo> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> <CaptionSettings Location="Top" /> </dx:LayoutItem> <dx:LayoutItem ColSpan="2" Caption="" ShowCaption="False"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxButton ID="btnSaveComments1" runat="server" Text="Save This Comment" AutoPostBack="false" RenderMode="Link"> <ClientSideEvents Click="function(s,e){ SaveComments('ProjectDetails'); }" /> </dx:ASPxButton> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> </dx:LayoutItem> <dx:LayoutItem ColSpan="2" Caption="" ShowCaption="False"> <LayoutItemNestedControlCollection> <dx:LayoutItemNestedControlContainer runat="server"> <dx:ASPxMemo ID="memPreviousProjectDetailsComments" ClientInstanceName="memPreviousProjectDetailsComments" runat="server" Width="98%" ReadOnly="true"> <Border BorderStyle="None" /> </dx:ASPxMemo> </dx:LayoutItemNestedControlContainer> </LayoutItemNestedControlCollection> </dx:LayoutItem> </Items> </dx:LayoutGroup> </Items> </dx:ASPxFormLayout>

There are numerous other formlayouts following the same format - hence the need to pass the section name and use it to generate the client side control names within the javascript in order to then get the selected values and texts (some of the comboboxs have text in the text fields, not just numbers).

The rest of the javascript works fine, as I've only just added the bit for the comboboxs.

Help!

Answers approved by DevExpress Support

created 10 years ago

Hello Tom,

I see that you save a string value to the newScore variable and call the GetSelectedItem method. It is necessary to access a client-side object to call this method as follows:

JavaScript
var myCombo = ASPxClientControl.GetControlCollection().GetByName(newScore); var myLbl = ASPxClientControl.GetControlCollection().GetByName(setScore); myLbl.SetText(myCombo.GetSelectedItem().text);

Also, please note if you set a control's Visible property to false, such a control is not rendered, and you cannot access it on the client side. Use the ClientVisible property if you wish to manipulate this control on the client side.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.