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

Clientside. get_text() is returning empty string

2 Answers 90 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 28 Mar 2011, 05:11 PM
Hi,

I'm trying to get my radcombobox (populated with checkboxes) to show what items are selected. Its similar to this demo:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx

However, my js code (copied from the above is simply returning empty strings with the .get_text() method.

Can anyone shed some light on why its returning nothing?

<telerik:RadComboBox ID="RadComboBox_User_Type" runat="server" EmptyMessage="Select Users" HighlightTemplatedItems="true"
            AllowCustomText="true" Width="225px">
            <Items>   
                <telerik:RadComboBoxItem 
                    ImagePath="../Images/OnTime_Fkeys/Access Control.png" 
                    Text_="Employee">
                </telerik:RadComboBoxItem>   
                <telerik:RadComboBoxItem 
                    ImagePath="../Images/OnTime_Fkeys/Access Control.png" 
                    Text_="Visitor">
                </telerik:RadComboBoxItem>
            </Items>
            <ItemTemplate>
                <div onclick="StopPropagation(event)" style="vertical-align: middle">
                    <asp:CheckBox runat="server" ID="chk1" Checked="false"/>
                    <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1">
                        <img src='<%# DataBinder.Eval(Container, "Attributes['ImagePath']") %>' alt="" style="vertical-align:text-top"/>
                        <%# DataBinder.Eval(Container, "Attributes['Text_']") %> 
                    </asp:Label>
                </div>
            </ItemTemplate>
        </telerik:RadComboBox>




protected void Page_Load(object sender, EventArgs e)
        {
  
            String script1 = "" +
                    "function StopPropagation(e) " +
                    "{" +
                        "e.cancelBubble = true;" +
                        "if (e.stopPropagation) " +
                        "{" +
                            "e.stopPropagation();" +
                        "}" +
                    "}";
  
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "LMP_Stop_Prop", script1, true);
  
            ClientScript.RegisterClientScriptBlock(Page.GetType(),"324nvik",
                "<script src=\"../Javascript/Live_Monitor/Live_Monitor.js\" type=\"text/javascript\"></script>");
  
            for (int i = 0; i < RadComboBox_User_Type.Items.Count; i++)
            {
                RadComboBox_User_Type.Items[i].DataBind();
  
            }
  
            foreach (RadComboBoxItem item in RadComboBox_User_Type.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("chk1");
                chk.Attributes.Add("onclick", "onCheckBoxClick(this)");
            }
  
        }
    }


Live_Monitor.js
function onCheckBoxClick(chk) {
  
    var combo = $find('RadComboBox_User_Type');
    var text = "";
    var values = "";
    var items = combo.get_items();
  
    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        var chk1 = $get("RadComboBox_User_Type" + "_i" + i + "_chk1");
  
        if (chk1.checked) {
            text += item.get_text() + ",";
            values += item.get_value() + ",";
        }
    }
      
    text = removeLastComma(text);
    values = removeLastComma(values);
      
  
    if (text.length > 0) {
        combo.set_text(text);
    }
    else {
        combo.set_text("Select Users");
    }
}
  
function removeLastComma(str) {
    return str.replace(/,$/, "");
}


Anyone any ideas????

Thanks,

Sunny

2 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 01 Apr 2011, 11:56 AM
Hello Sunil,

You should use the following:
item.get_attributes().getAttribute("Text_")
instead of
item.get_text()

Regards,
Dimitar Terziev
the Telerik team
0
Sunil
Top achievements
Rank 1
answered on 07 Apr 2011, 07:54 PM
Thank you that worked :)
Tags
ComboBox
Asked by
Sunil
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Sunil
Top achievements
Rank 1
Share this question
or