Problem Assigning Value to ListBox in Control Designer
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?
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
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?
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,