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

RADCombobox Remember items even after .clearItems();. Not Displayed on Page. But Uploading on Postback,,Duplicate value Problem

5 Answers 112 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Vishmay
Top achievements
Rank 1
Vishmay asked on 18 Jul 2014, 07:50 AM
Stepwise Explanation

 ddlTest.clearItems();
 ddlTest.trackChanges();
ddlTest.clearSelection();

   for (var j = 0; j < heat_no.length - 1; j++) {
                                        var comboItem = new Telerik.Web.UI.RadComboBoxItem();

                                        comboItem.set_text(heat_no[j]);
                                        comboItem.set_value(heat_no[j]);

                                        ddl_cast_no.get_items().add(comboItem);
                                    }
  ddlTest.commitChanges();

1. Above Javascript Code is Executed and My Combobox is filled Perfectly
2. Now if this Code is executed again it Displays new results that is ok
3. Let me execute again .. No Problem in Display
4. I am Making a Postback on server for Some other work
5. After postback is Shows me my combobox has 3 times duplicated values(Not that we have executed it 3 times).

If the Code is two times executed the value will be 2 times Duplicate executed
If the Code is 5 times executed the value will be 5 times Duplicate executed

I want it Without Duplicate
Hope You Got My Point
Reply me as fast as Possible

5 Answers, 1 is accepted

Sort by
0
Vishmay
Top achievements
Rank 1
answered on 18 Jul 2014, 08:04 AM
Sorry about a Bit Mistake and uncomplete information

ddlTest.clearItems();
 ddlTest.trackChanges();
ddlTest.clearSelection();
   for (var j = 0; j < heat_no.length - 1; j++) {
                                        var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                                        comboItem.set_text(heat_no[j]);
                                        comboItem.set_value(heat_no[j]);
                                        ddlTest.get_items().add(comboItem);
                                    }
  ddlTest.commitChanges();

Mistake  ddl_cast_no change to ddlTest

Note: I have Tried AppendDataBoundItems="true" and "false"
i m using Telerik.Web.UI_2011_2_712_Dev
Thanks
0
Shinu
Top achievements
Rank 2
answered on 18 Jul 2014, 10:06 AM
Hi Vishmay,

Unfortunately I couldn't replicate the issue at my end. The provided code is working fine for me. Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server">
</telerik:RadComboBox>
<telerik:RadButton ID="rbtnAddItems" runat="server" Text="Add Items" AutoPostBack="false"
    OnClientClicked="addItem">
</telerik:RadButton>
<telerik:RadButton ID="rbtnPostBack" runat="server" Text="PostBack">
</telerik:RadButton>

JavaScript:
function addItem() {
    var ddlTest = $find("<%=RadComboBox1.ClientID%>");
    ddlTest.clearItems();
    ddlTest.trackChanges();
    ddlTest.clearSelection();
    for (var j = 0; j < 3; j++) {
        var comboItem = new Telerik.Web.UI.RadComboBoxItem();
        comboItem.set_text("Item" + j);
        comboItem.set_value(j);
        ddlTest.get_items().add(comboItem);
    }
    ddlTest.commitChanges();
}

Thanks,
Shinu.
0
Vishmay
Top achievements
Rank 1
answered on 19 Jul 2014, 06:46 AM
I have Test Your Code on New Page.  And It is having Same Error

1. I click Add item when Combobox was Empty
2. Then 3 Items Were Filled. I make Postback -->3 Items(Item 0,1,2)
3. I Clicked Add item +2 Times (Total 3 Times) --> Checked Display-->3 Items(Item 0,1,2)
4. Clicked Postback-->Completed postback -->Result was....Check All ScrennShots
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Jul 2014, 02:45 AM
Hi Vishmay,

Please do the following modification in your JavaScript which works fine at my end.

JavaScript:
function addItem() {
    var ddlTest = $find("<%=RadComboBox1.ClientID%>");
    ddlTest.trackChanges();
    ddlTest.clearItems();
    ddlTest.clearSelection();
    for (var j = 0; j < 3; j++) {
        var comboItem = new Telerik.Web.UI.RadComboBoxItem();
        comboItem.set_text("Item" + j);
        comboItem.set_value(j);
        ddlTest.get_items().add(comboItem);
    }
    ddlTest.commitChanges();
}

Thanks,
Shinu.
0
Vishmay
Top achievements
Rank 1
answered on 22 Jul 2014, 01:54 PM
Thank You Friend,
Your suggestion works correctly. Thanks for the help.
New solution works for me.

I Dont Know you are Team Member or telerik or not, But Make a favor
In your new answer, Please Highlight Your Changes or write it below code
so other reader can identify what change you did in new one.
and if possible please change title of my topic. it is meaningless.
i have seen many people working on same problem with diff. Keywords.
This answer may be helpful to them
If Possible please change on same post(marked as answer)
Thanks
Tags
ComboBox
Asked by
Vishmay
Top achievements
Rank 1
Answers by
Vishmay
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or