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

RadMaskedTextBox OnKeyPress not working correctly.

4 Answers 142 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 25 Jun 2011, 12:54 PM
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>

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jun 2011, 01:03 PM
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.
0
Ian
Top achievements
Rank 1
answered on 27 Jun 2011, 01:24 PM
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
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Jun 2011, 11:02 AM
Hello Ian,

Try setting the PromptChar and DisplayPromptChar.

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

Thanks,
Shinu.
0
Ian
Top achievements
Rank 1
answered on 28 Jun 2011, 11:39 AM
Hi Shinu

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

Ian
Tags
Input
Asked by
Ian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ian
Top achievements
Rank 1
Share this question
or