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

How to remove html tags from Radcombobox on event of onblur

1 Answer 70 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 2
Manish asked on 14 Oct 2011, 07:16 AM
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

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 18 Oct 2011, 08:26 AM
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
Tags
ComboBox
Asked by
Manish
Top achievements
Rank 2
Answers by
Ivana
Telerik team
Share this question
or