Rad Combobox setting special Charecters

3 posts, 0 answers
  1. Suraj
    Suraj avatar
    14 posts
    Member since:
    Feb 2008

    Posted 19 Jul 2013 Link to this post

    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. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 24 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 25 Jul 2013 Link to this post

    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.
Back to Top