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

RadComboBox removes spaces between words

3 Answers 234 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Oleg Yaroshevych
Top achievements
Rank 1
Oleg Yaroshevych asked on 29 Aug 2008, 03:07 PM
Hello,

I am using RadComboBox with EnableLoadOnDemand property set to "True". I am handling ItemsRequested event to add appropriate items in combo box.

The problem is that if item's text contains more than one space between words, spaces are removed. For example, if item contains "Test  Test" text (note 2 spaces between the words), RadComboBox.Text property returns "Test Test" text (1 space). I was able to reproduce this problem in IE 7.0 and Safari 3.1.2 for Windows. FF 3.0 works fine (it returns all spaces).

Please check my code. Select "Test  Test2" item and check how many spaces will be returned (I replace spaces with '.').

Best regards, Oleg.


My configuration
Telerik For ASP.NET AJAX 2008.01.0619.35
Windows XP Pro SP2
Visual Studio 2008
IE 7.0 - Fails
Safari 3.1.2 for Windows - Fails
FF 3.0 - OK


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server">
    </telerik:RadScriptManager>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="True">
    </telerik:RadComboBox>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>


Default.aspx.cs

using System;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    RadComboBox1.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(RadComboBox1_ItemsRequested);
  }

  void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
  {
    RadComboBox comboBox = (RadComboBox)sender;

    comboBox.Items.Add(new RadComboBoxItem("Test"));
    comboBox.Items.Add(new RadComboBoxItem("Test Test"));
    comboBox.Items.Add(new RadComboBoxItem("Test  Test2")); // note: 2 spaces

    e.EndOfItems = true;
  }

  protected void Button1_Click(object sender, EventArgs e)
  {
    Label1.Text = RadComboBox1.Text.Replace(" ", ".");
  }
}

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 29 Aug 2008, 03:24 PM
Hi Oleg Yaroshevych,

I suggest that you use &nbsp; instead of a space.


All the best,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Oleg Yaroshevych
Top achievements
Rank 1
answered on 29 Aug 2008, 03:37 PM
Veskoni,

If I use &nbsp; instead of space when filling RadComboBox.Items in ItemsRequested handler, dropdown items and RadComboBox.Text will contain "&nbsp;" string instead of space. I tested it.

Best regards, Oleg Yaroshevych.
0
Veselin Vasilev
Telerik team
answered on 01 Sep 2008, 02:47 PM
Hi Oleg Yaroshevych,

Please use the HtmlDecode method like this:

string text = "there are more &nbsp;&nbsp;&nbsp;&nbsp; spaces"
RadComboBox1.Items.Add(new RadComboBoxItem(Server.HtmlDecode(text))); 

I hope this helps.

Regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Oleg Yaroshevych
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Oleg Yaroshevych
Top achievements
Rank 1
Share this question
or