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

Rad Combobox setting special Charecters

2 Answers 118 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Suraj
Top achievements
Rank 1
Suraj asked on 19 Jul 2013, 07:57 PM
I have an issue with setting text to the combobox. If I set any text with "<,>" characters while submitting I am getting validation errors. I am adding the code so that you can reproduce. I cannot turn off validaterequest from the page.

HTML Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="true" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
    <script>
        var RadFausTree = "";
        function SFAUS() {
            val = "<ALL>/<ALL>/<ALL>";
            combo = $find(RadFausTree);
            combo.trackChanges();
            var escapedText = htmlEscape(val);
            //esc = val;
            //alert(escapedText);
            combo.set_text(escapedText);
            combo.set_value("");
            cancelDropDownClosing = false;
            combo.commitChanges();
            combo.hideDropDown();
 
        }
        function htmlEscape(str) {
            return String(str)
                    .replace(/&/g, '&')
                    .replace(/"/g, '"')
                    .replace(/'/g, ''')
                    .replace(/</g, '<')
                    .replace(/>/g, '>');
        }
 
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server"></asp:ScriptManager>
    <div>
     <telerik:RadComboBox ID="RadFausTree" Width="100%" Height="300px"
                                               AllowCustomText="true" EmptyMessage="Select The Faus"
                                               runat="server"/>
                        <input type="button" value="Set Text" onclick="SFAUS()" />
        <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"/>
    </div>
    </form>
</body>
</html>

C# Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      RegisterStartupScript ("strKey", "<script>RadFausTree='"+RadFausTree.ClientID+"';</script>");
    }
    protected void btnSubmit_Click (object sender, EventArgs e)
    {
       
    }
}

Attaching the result that I am getting.

2 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 24 Jul 2013, 03:14 PM
Hello,

In order to implement such functionality we would try to encode the selected item text on the client side in order to send the RadComboBox text value without any exceptions and decode that value on the server so it will be human readable. I am afraid that we would need a bit more time to implement such scenario. I would like to assure you that I will contact you as soon as there is an update regarding your question. 

Thank you for understanding and cooperation.

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Boyan Dimitrov
Telerik team
answered on 25 Jul 2013, 11:08 AM
Hello,

As I mentioned in my very last post one possible workaround in your case would be to encode the RadComboBox text value just before submitting the form to the server. In order to keep that value human readable after the page is sent from the server back to the client you could perform a server-side decoding as shown in the attached sample project.  That way you will be allowed to select an element with text value containing "<" or ">" characters and send it to the server successfully.


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Ajax
Asked by
Suraj
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or