+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Problem Assigning Value to ListBox in Control Designer

Problem Assigning Value to ListBox in Control Designer

4 posts, 0 answered
  1. Justin
    Justin avatar
    2 posts
    Registered:
    26 May 2008
    17 May 2013
    Link to this post
    I have a ListBox server control in a control designer, but I'm having some trouble assigning the value to the control when it loads in Sitefinity.  It seems to set the value without any issue, and all of the other controls in the control designer work as expected.   I had this control set up as a DropDownList initially, and everything worked, but I need to swap it out for a ListBox to allow for multiple selections. 

    I have a property of type string called Test in my widget.  I am storing the user's selections as a list of values in a single string, separated by commas.

    Here is what I have in my control designer:

    <asp:ListBox ID="lbTest" runat="server" SelectionMode="Multiple" ClientIDMode="Static">
    <asp:ListItem Value="1">Item 1</asp:ListItem>
    <asp:ListItem Value="2">Item 2</asp:ListItem>
    <asp:ListItem Value="3">Item 3</asp:ListItem>
    <asp:ListItem Value="4">Item 4</asp:ListItem>
    </asp:ListBox>

    Here is what is in the applyChanges: function () section of the control designer JavaScript file:

    var array = [];
    jQuery('#lbTest :selected').each(function (i, selected) {
        array[i] = jQuery(selected).text();
    });
    controlData.Test = array.join(',');

    Here is what is in the refreshUI: function () section of the control designer JavaScript file:

    alert(controlData.Test);  // this works and displays the values that were previously saved
    var array = controlData.Test.split(',');
    // I've done testing here to ensure that the array has been populated
    if (jQuery("#lbTest").length > 0) {
      jQuery("#lbTest").val(array );
    } else {
      alert('could not find #lbTest');  // Just in case the control wasn't found
    }

    I have tested all of the jQuery outside of Sitefinity and it works as expected.  Sitefinity is also storing the value and I am able to retrieve it, but for some reason, I cannot assign the values back to the ListBox control.  I have used alerts in various places to ensure that the array variable is actually an array, and that it has items.

    Is there something I'm missing?




  2. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    22 May 2013
    Link to this post
    Hello,

    Would you mind attaching your control here so I can take a look at it? Also are you seeing anything in your error logs? App_data/sitefinity/logs is where to look.

    Thanks in advance.

    Regards,
    Patrick Dunn
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Justin
    Justin avatar
    2 posts
    Registered:
    26 May 2008
    23 May 2013 in reply to Patrick Dunn
    Link to this post
    Hi Patrick,

    I can't attach a .zip file to this thread.  I get an error saying that the only allowed types are .gif, .jpg, .jpeg, and .png.

    Can I send it to you some other way?
  4. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    24 May 2013
    Link to this post
    Hi Justin,

     You can submit a support ticket with the zip file or I can provide you FTP information in a private support ticket. We can then update this thread with the final solution for others to see.

    Regards,
    Patrick Dunn
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered