RadMaskedTextBox OnKeyPress not working correctly.

5 posts, 1 answers
  1. Ian
    Ian avatar
    5 posts
    Member since:
    Sep 2012

    Posted 25 Jun 2011 Link to this post

    I have a simple form with a radMaskedTextBox.  The clientside event is firing correcly, but the control does not put valid characters in to the text box.  I have even tried getting it to accept any value  but it seems that the keypress event is preventing any character from being added.

    Any suggestions would be welcome as I am against a brickwall with this one now.

    Example page added.
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
     
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript">
            function keyPress(sender, eventArgs) {
               var c = eventArgs.get_keyCode();
     
               if ((c < 48) || (c > 57)) {
                  eventArgs.set_cancel(false);
                    
               }
     
            }
       
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
            </telerik:RadScriptManager>
         
            <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server">
                <ClientEvents OnKeyPress="keyPress" />
            </telerik:RadMaskedTextBox>
         
        </div>
        </form>
    </body>
    </html>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Jun 2011 Link to this post

    Hello Ian,

    This behavior is not because of the client event you attached. RadMaskedTextBox has not been designed to work without a mask, as this defeats its purpose. In order to work RadMaskedTextBox you need to set the mask.

    Thanks,
    Shinu.
  3. Ian
    Ian avatar
    5 posts
    Member since:
    Sep 2012

    Posted 27 Jun 2011 Link to this post

    Hi Shinu

    Thanks for the response.  I understand what you are saying.  The only problem is that my client does not want to see the PromptChar in the box.  Fussy I know.  Hence the reason I was trying without a Mask.  When I add the Mask in e.g. ############## then the numbers show up, but I have no need for the client side code as the content is then controlled by the Mask.

    Is there anyway to use the control with a mask without having PromptChar showing?

    Thanks

    Ian
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jun 2011 Link to this post

    Hello Ian,

    Try setting the PromptChar and DisplayPromptChar.

    <telerik:RadMaskedTextBox  PromptChar=" " DisplayPromptChar=" "  />

    Thanks,
    Shinu.
  5. Ian
    Ian avatar
    5 posts
    Member since:
    Sep 2012

    Posted 28 Jun 2011 Link to this post

    Hi Shinu

    That is exactly what I needed, thank you very much.

    Ian
Back to Top