Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a telerik datepicker as below:


C#
<div class="sxlb">
                               <asp:Label ID="lblLastBackgroundCheckedDate" runat="server" AssociatedControlID="dpLastBackgroundCheckedDate"
                                   Text="Last Background Checked Date"></asp:Label></div>
                           <div class="sxlm">
                               <lpsfs:SysXDatePicker  runat="server" ID="dpLastBackgroundCheckedDate" DateInput-ReadOnly="true"
                                   DateInput-DateFormat="MM-dd-yyyy" Width="99%">
                                   <ClientEvents  önPopupClosing="FocusOnPopUpButton" />
                                   <Calendar ID="calLastBackgroundCheckedDat"  runat="server" EnableKeyboardNavigation="true"
                                       CausesValidation="false">
                                   </Calendar>
                               </lpsfs:SysXDatePicker>
                               <div class="vldx">
                                   <asp:CompareValidator ID="cmpLastBackgroundCheckedDate" ControlToValidate="dpLastBackgroundCheckedDate"
                                       class="errmsg" ValidationGroup="grpSupplierInformation" Operator="LessThanEqual"
                                       Display="Dynamic" ValueToCompare='<%# DateTime.Today.ToShortDateString() %>'
                                       Type="Date" runat="server" ErrorMessage='<%#SysXUtils.GetMessage(ResourceConst.SUPPLIER_INFORMATION_LAST_BACKGROUND_CHECKED_DATE) %>'></asp:CompareValidator>
                               </div>
                           </div>


now if i press backspace on this,it is not working,
I tried to do the below thing::

C#
DateInput-ReadOnly="false"
EnableKeyboardNavigation="false"

but if i do this then,if the user enters alphabet or Chars like -,/ it is giving error.
I want that user cannot enter the date on its own,he has to pick it from the calender.
any help would be deeply regarded.
Posted

1 solution

Solved it by masking the control :

ASP:
<telerik:RadDatePicker ... DateInput-ClientEvents-OnKeyPress="KeyPress">


JavaScript:

XML
<script type="text/javascript">
  function KeyPress(sender, eventArgs) {
     var keyPressed = eventArgs.get_keyCode();
     if ((keyPressed > 64 && keyPressed < 91)
        || (keyPressed > 96 && keyPressed < 123)) {
         eventArgs.set_cancel(true)
     }
  }
</script>



Quote:
Note that you can disable additional keyboard keys by using their ASCII code as showed in the example.(65-90 for capitalized letters and 97-122 for small letters).
 
Share this answer
 

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