How to remove html tags from Radcombobox on event of onblur

2 posts, 0 answers
  1. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 14 Oct 2011 Link to this post

    Hi,

    I am using rad combobox and i want to do that when any <HTML> tag insert in combobox after that user go to click GO button than it should become HTML. I am able to do it on simple asp text box but not able to do it on combobox.

    Code example:

    On TextBox :
      <script type="text/javascript">
            //remove space from log text box
    function RemoveSpecialSymbols(id) {
                var objid = document.getElementById(id);
                if (objid)
                    objid.value = html2entities(objid.value);
            }

            function html2entities(sometext) {
                var re = /[<>]/g
                //    if (sometext.length > 2500)
                //        sometext = sometext.substr(0, 2500);
                return sometext.replace(re, function (m) { return replacechar(m) })
            }

            function replacechar(match) {
                if (match == "<")
                    return ""
                else if (match == ">")
                    return ""
            }
      </script>
    <asp:TextBox ID="txtEmail" runat="server" TabIndex="1" MaxLength="50" SkinID="RequiredTextBox" onkeydown="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {RemoveSpecialSymbols(this.id);}};" onblur="RemoveSpecialSymbols(this.id);" ></asp:TextBox>

    Same thing i want to do it on RadCombobox....

         <telerik:RadComboBox ID="RCBSearch" runat="server" Width="250px" Height="150px" Text=""
                        ShowToggleImage="false" EmptyMessage="Search by tags, products, business name"
                        EnableLoadOnDemand="true" ShowMoreResultsBox="true" Style="float: left; margin: 0;
                        padding: 0;" EnableVirtualScrolling="true" ShowDropDownOnTextboxClick="false"
                        onkeydown="PressKeyForProfile(this, event)">
                        <WebServiceSettings Method="GetCompanyNames" Path="wsSellWithMe.asmx" />
                    </telerik:RadComboBox>


    But it is sowing some kind of javascript error...

    "Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500"

    Thanks
    Manish
  2. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 18 Oct 2011 Link to this post

    Hello Manish,

    The following code snippet should work for your scenario:
    function PressKeyForProfile(event) {
            if (event.which || event.keyCode) {
                if ((event.which == 13) || (event.keyCode == 13)) {
                    var combo = $find("<%= RCBSearch.ClientID %>");
                    var inputArea = combo.get_inputDomElement();
                    if (inputArea)
                        inputArea.value = html2entities(inputArea.value);
                }
            }
    }

    Or,  if you want to implement the same functionality on ClientBlur you should use the following approach:
    function onBlur(sender, args) {
            var inputArea = sender.get_inputDomElement();
            if (inputArea)
                inputArea.value = html2entities(inputArea.value);
    }

    The RadComboBox is defined as follows:
    <telerik:RadComboBox ID="RCBSearch" runat="server" Width="250px" Height="150px" Text=""
                        ShowToggleImage="false" EmptyMessage="Search by tags, products, business name"
                        EnableLoadOnDemand="true" ShowMoreResultsBox="true" Style="float: left; margin: 0;
                        padding: 0;" EnableVirtualScrolling="true" ShowDropDownOnTextboxClick="false"
                        onkeydown="PressKeyForProfile(event)" OnClientBlur="onBlur">
                        <webservicesettings method="getcompanynames" path="wssellwithme.asmx" />
    </telerik:RadComboBox>

    More information of RadComboBox's client-side programming, can be found at the following link: RadComboBox: Client-Side Programming.

    Hope this helps.

    All the best,
    Ivana
    the Telerik team
    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 their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top