Edited items not available on server side

4 posts, 0 answers
  1. Timothy
    Timothy avatar
    6 posts
    Member since:
    Dec 2014

    Posted 25 Dec 2014 Link to this post

    I written some client side code that edits the Item Collection of a RadDropDownList.
    The problem is that when I do a postback, the serverside only detects the original list.

    I don't see what I've done wrong.
    This is what I have so far:
    var ddl = $find("<%=_ddlLidsIndicators.ClientID%>");
    ddl.get_items().clear();
     
    var selectItem = new Telerik.Web.UI.DropDownListItem();
    selectItem.set_text("Select...");
    ddl.get_items().add(selectItem);
     
    $.each(data, function (index, value) {
        var newItem = new Telerik.Web.UI.DropDownListItem();
        newItem.set_text(value);
        newItem.set_value(index);
        ddl.get_items().add(newItem);
    });
     
    var otherItem = new Telerik.Web.UI.DropDownListItem();
    otherItem.set_text("Other");
    ddl.get_items().add(otherItem);
     
    ddl.commitChanges();

     

  2. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 26 Dec 2014 Link to this post

    Hello,

    You have to call the trackChanges() method of the DropDownList control before you make your modifications, and commitChanges() after the modifications. In your sample you are only calling commitChanges(), which is why it's not working. Here's the modified version:
    var ddl = $find("<%=_ddlLidsIndicators.ClientID%>");
                 
    ddl.trackChanges();
     
    ddl.get_items().clear();
     
    var selectItem = new Telerik.Web.UI.DropDownListItem();
    selectItem.set_text("Select...");
    ddl.get_items().add(selectItem);
     
    $.each(data, function (index, value) {
        var newItem = new Telerik.Web.UI.DropDownListItem();
        newItem.set_text(value);
        newItem.set_value(index);
        ddl.get_items().add(newItem);
    });
     
    var otherItem = new Telerik.Web.UI.DropDownListItem();
    otherItem.set_text("Other");
    ddl.get_items().add(otherItem);
     
    ddl.commitChanges();


    Regards,
    Bozhidar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Timothy
    Timothy avatar
    6 posts
    Member since:
    Dec 2014

    Posted 30 Dec 2014 in reply to Bozhidar Link to this post

    Thank you Bozhidar,
    This is mostly working.

    I've got a button that makes a postback.
    On the serverside, I can see all the new items now..

    The problem is that on the first postback, It doesn't detect the correct SelectedItem.
    On the second postback, it does correctly see the SelectedItem.

    Do you have any thoughts on what could cause this?
  5. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 02 Jan 2015 Link to this post

    Hi Timothy,

    You should set the selected item after you have added it to the items collection as for example in the code below:
    var ddl = $find("<%=_ddlLidsIndicators.ClientID%>");
                    var data = ["one", "two"];
                    ddl.trackChanges();
     
                    ddl.get_items().clear();
     
                    var selectItem = new Telerik.Web.UI.DropDownListItem();
                    selectItem.set_text("Select...");
                    
                    ddl.get_items().add(selectItem);
                    selectItem.set_selected(true);
     
                    var otherItem = new Telerik.Web.UI.DropDownListItem();
                    otherItem.set_text("Other");
                    ddl.get_items().add(otherItem);
     
                    ddl.commitChanges();

    Hope this will help you solve the issue.

    Regards,
    Plamen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top