Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following :
XML
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    UICulture="ar-SA" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="cc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    &nbsp;<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        function txtOnKeyPress(txt1)
         {
//            if (txt1 != 'undefined')
             //            {

             txt1.value = convertDigitIn(txt1.value);

//            }
         }

//Assuming that the number you wish to convert is already in a string, then something like the following snippet of code will work:

function convertDigitIn(enDigit){ // PERSIAN, ARABIC, URDO
    var newValue="";
    for (var i=0;i<enDigit.length;i++)
    {
        var ch=enDigit.charCodeAt(i);
        if (ch>=48 && ch<=57)
        {
            // european digit range
            var newChar=ch+1584;
            newValue=newValue+String.fromCharCode(newChar);
        }
        else
            newValue=newValue+String.fromCharCode(ch);
    }
    return newValue;
}
    </script>
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="txtOnKeyPress(this);"
        TextMode="MultiLine" Height="600px" Width="600px" ></asp:TextBox>

 <%--
    <asp:HtmlEditorExtender ID="htmlEditorExtender1" TargetControlID="TextBox1"
        runat="server" EnableSanitization="false" >
    </asp:HtmlEditorExtender>  --%>

</asp:Content>

Now txtOnKeyPress is working fine when I remove the comments the txtOnKeyPress stop working
I need the JavaScript code with TextEditor too.
Posted
v2
Comments
JoCodes 11-Dec-13 22:51pm    
When removing which comments? if (txt1 != 'undefined')?
JoCodes 11-Dec-13 22:53pm    
Any reason not using OnClientChange event of the editor?
Please check my answer. :)
Please check my answer. :)
Hamza Dweikat 16-Dec-13 8:57am    
I have problem when I press enter no new line create and the the text dosent wrab ?

1 solution

Finally, after all my research, I did it. Let me explain...

Problem


When you use HtmlEditorExtender, TextBox1 is hided.
HTML
<textarea style="height: 600px; width: 600px; display: none; visibility: hidden;" onkeyup="txtOnKeyPress(this);" id="TextBox1" cols="20" rows="2" name="TextBox1"></textarea>

So, when you attach a keyup event to that TextBox, it won't work.

Approach


Many new divs are created to facilitate the Editor. The main div where you enter the text is as follows.
HTML
<div contenteditable="true" id="TextBox1$HtmlEditorExtenderBehavior_ExtenderContentEditable" style="height: 80%; overflow: auto; clear: both;" class="ajax__html_editor_extender_texteditor"></div>


So, we need to provide keyup for this div only.

Solution


To do that, we have to place the below script inside Body tags. Putting this in Head tag will not work, as the HtmlEditorExtender is not loaded at that time.
HTML
<script type="text/javascript">
    Sys.Application.add_load(function () {
        var htmlEditorBox = $('.ajax__html_editor_extender_texteditor');
        
        htmlEditorBox.keyup(function () {
            this.textContent = convertDigitIn(this.textContent);
        });
    });
</script>

The code is quite self explanatory. It gets that main Editor div by its class name. Then its content according to your logic.

Note


1. I have tested it at my end and it is working fine.
2. Don't forget to include the jQuery file inside head tags. You can also directly include the below script...
HTML
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
 
Share this answer
 
Comments
Hamza Dweikat 12-Dec-13 2:48am    
Thanks It's Working :)
Glad to hear that. :) Please up-vote and accept the answer.

Thanks,
Tadit.
RaisKazi 12-Dec-13 10:09am    
My 5! Very well explained.
Thanks a lot. :) :)
VICK 23-Dec-13 7:52am    
Hi Tadit Dash..
I am trying to bind a textbox enter key event with button click by doing the following in PageLoad

txtMsg.Attributes.Add("onkeydown",
"if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSend.UniqueID + "').click();return false;}} else {return true}; ");



and that is working fine.. that when i write anything in textbox and click enter. it raised the button click event.
But now i wana use HTML EDITOR EXTENDOR of ajax.
and I have tried your solution but unable to understand and implement it completely.

SO can you guide me a bit more???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900