This is a migrated thread and some comments may be shown as answers.

[Solved] RadComboBox with ItemTemplate loses postback data

3 Answers 226 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Billy
Top achievements
Rank 1
Billy asked on 23 Jun 2009, 11:48 PM
Hello,

I have a radcombobox with an ItemTemplate that contains a checkbox and a label.

                                <telerik:RadComboBox ID="cbM0016" runat="server"  
                                    EmptyMessage="Select Branch" HighlightTemplatedItems="true" 
                                    AllowCustomText="true" Enabled="false" Skin="Outlook" Width="100%" > 
                                    <ItemTemplate> 
                                        <asp:CheckBox runat="server" ID="chk1" Checked="true" onclick="onCheckBoxClickM0016(this)"/> 
                                        <asp:Label runat="server" ID="lbl1" Text='<%#DataBinder.Eval(Container.DataItem, "BranchNameAndID")%>'/> 
                                    </ItemTemplate> 
                                </telerik:RadComboBox> 
 


One of the checkboxes (the "ALL" checkbox) will trigger all other checkboxes to be checked and store all the associated values as a comma delimited string.  This is being done in the javascript.  The problem I'm having is that occasionally my values are not being posted back to the server.  

Repro steps are:  
Load the form (default selection works fine)
Unselelct several checkboxes and submit the form (works fine)
Select the "ALL" checkbox (form does not submit the updated values)

I have added alerts in the javascript that show that the values are being set on the client side.  Here is that code...

function onCheckBoxClickM0016(sender) { 
            var combo = $find("<%= cbM0016.ClientID %>"); 
            //holds the text of all checked items 
            var text = ""
            //holds the values of all checked items 
            var values = ""
            //get the collection of all items 
            var items = combo.get_items(); 
 
            //get the ALL checkbox 
            var chk1 = $get(combo.get_id() + "_i0" + "_chk1"); 
            if (chk1.checked && sender.id == "cbM0016_i0_chk1") { 
                text = "ALL"
                //enumerate all items 
                for (var i = 1; i < items.get_count(); i++) { 
                    var item = items.getItem(i); 
                    //get the checkbox element of the current item 
                    var chk2 = $get(combo.get_id() + "_i" + i + "_chk1"); 
                    chk2.checked = true
                    values += item.get_value() + ","
                } 
            } 
            else { 
                var count = 0; 
                //enumerate all items 
                for (var i = 1; i < items.get_count(); i++) { 
                    var item = items.getItem(i); 
                    //get the checkbox element of the current item 
                    var chk2 = $get(combo.get_id() + "_i" + i + "_chk1"); 
                    if (chk2.checked) { 
                        count += 1; 
                        text += item.get_text() + ","
                        values += item.get_value() + ","
                    } 
                } 
                if (count == i - 1 && sender.id != "cbM0016_i0_chk1") { 
                    chk1.checked = true
                } 
                else { 
                    chk1.checked = false
                } 
            } 
 
            //remove the last comma from the string 
            text = removeLastComma(text); 
            values = removeLastComma(values); 
 
            if (text.length > 0) { 
                //set the text of the combobox 
                if (chk1.checked) { 
                    combo.set_text("ALL"); 
                } else { 
                    combo.set_text(text); 
                } 
            } 
            else { 
                //all checkboxes are unchecked 
                //so reset the controls  
                combo.set_text(""); 
            } 
 
            combo.set_value(values); 
        } 


Please help.

-Billy

3 Answers, 1 is accepted

Sort by
0
Billy
Top achievements
Rank 1
answered on 25 Jun 2009, 07:14 PM
I found a workaround for this.

I'm using the asp HiddenField control to store the values and pass them back to the server. 

I'm still unsure why the RadComboBox was not retaining it's values.

-Billy
0
Veselin Vasilev
Telerik team
answered on 29 Jun 2009, 06:24 AM
Hello Billy,

I believe the problem is in the last line:

            combo.set_value(values); 

because the combo's item does not have a Value = values.
So, you can try setting the value of the item instead of the combo:

combo.get_items().getItem(0).set_value(values);


All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Billy
Top achievements
Rank 1
answered on 30 Jun 2009, 07:13 PM
Thank you!  I will give this a try.

-Billy
Tags
ComboBox
Asked by
Billy
Top achievements
Rank 1
Answers by
Billy
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or