如何启用退格键,删除到maskededitextender日期字段

时间:2018-03-07 10:03:31

标签: c# asp.net .net asp.net-mvc ajaxcontroltoolkit

我有一个文本框作为日期字段。但是由于蒙面编辑器扩展器,我无法在chrome或firefox退格编辑日期,删除在chrome或firefox中无效。

代码低于

   <asp:TextBox ID="txtStartDate"  CssClass="txtStartDate" runat="server" MaxLength="10"    onkeydown="return allowBackSpace(event);" />&nbsp;
        <asp:RequiredFieldValidator ID="startDateRequiredFieldValidator" runat="server" ValidationGroup="Dates" ControlToValidate="txtStartDate"
                                EnableClientScript="True" Display="None" Text="*" ErrorMessage="Start date is required."/>
        <asp:CompareValidator ForeColor="Red"  id="startDateCompareValidator1" runat="server" Type="Date" 
                                ValidationGroup="Dates" Display="None" EnableClientScript="True"
                                Operator="DataTypeCheck" ControlToValidate="txtStartDate" Text="*"
                                ErrorMessage="Start date is not valid or is in an incorrect format. Please use the format yyyy-MM-dd."/>
        <asp:RangeValidator id="ReturnDateRangeValidator" runat="server" ControlToValidate="txtStartDate" ValidationGroup="Dates"
                            MinimumValue="2005-01-01" MaximumValue="2050-01-01"  Display="None" EnableClientScript="True" Text="*"
                            ErrorMessage="Start date is too far back in time or it is to far in future, please enter a more feasible date."/>
    <cc1:CalendarExtender ID="Calendarextender2" runat="server" Format="yyyy-MM-dd" PopupButtonID="Image2"
        TargetControlID="txtStartDate" FirstDayOfWeek="Monday">
    </cc1:CalendarExtender>
    <cc1:MaskedEditExtender ID="maskStartDate" runat="server" Century="2000" CultureName="sv-SE"
    Mask="9999/99/99" MaskType="Date" TargetControlID="txtStartDate" AutoComplete="False" />
<cc1:MaskedEditExtender ID="maskStartTime" runat="server" Century="2000" CultureName="sv-SE"
    Mask="99:99" MaskType="Time" TargetControlID="txtStartTime" AutoComplete="false" />
<cc1:MaskedEditExtender ID="maskStopDate" runat="server" Century="2000" CultureName="sv-SE"
    Mask="9999/99/99" MaskType="Date" TargetControlID="txtStopDate" AutoComplete="False" />
<cc1:MaskedEditExtender ID="maskStopTime" runat="server" Century="2000" CultureName="sv-SE"
    Mask="99:99" MaskType="Time" TargetControlID="txtStopTime" AutoComplete="false" />

我编写了javascript onleydown函数以允许退格,但它无效..

   <script type="text/javascript" language="javascript">
      function allowBackSpace(event) {

        var key = window.event ? event.keyCode : event.which;
        //alert(key);
        if (event.keyCode == 8) {
          alert(key);
           return true;
        }
        else if (key < 48 || key > 57) {
          return false;
        }
        else return false;
        }
     </script>

onkeydown call

     <asp:TextBox ID="txtStartDate"  CssClass="txtStartDate" runat="server" MaxLength="10"    onkeydown="return allowBackSpace(event);" />

1 个答案:

答案 0 :(得分:1)

sollution

下载ajaxcontroltoolkit的最新版本18.0.0。他们将此错误解决为新的更新版本