how to enable backspace,delete into maskededitextender date field

北城余情 提交于 2021-02-07 08:37:52

问题


I have a textbox as a date field . but due masked editor extender I can't edit dates in chrome or firefox backspace and delete is not working in chrome or firefox .

codes are below

   <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" />

I wrote javascript onleydown function to allow backspace but it's not working..

   <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:


sollution

download ajaxcontroltoolkit's latest version 18.0.0 . they solved this error into new updated version



来源:https://stackoverflow.com/questions/49149067/how-to-enable-backspace-delete-into-maskededitextender-date-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!