如何启用退格键,在asp中删除:Chrome中的TextBox

时间:2018-01-29 10:05:56

标签: c# asp.net google-chrome

我的代码就像这样

<asp:TextBox ID="txtStartDate" CssClass="txtStartDate" runat="server" MaxLength="10"   />&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>

我有一个日期字段,我可以使用删除,退格到IE但我无法进入Chrome。我的问题是如何启用退格键,删除Chrome。有关此

的任何信息都会有所帮助

1 个答案:

答案 0 :(得分:1)

你可以使用JQuery吗

这是带有事件按键的文本框

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

一些脚本

function allowBackSpace(val) {
    var keyCodeEntered = (event.which) ? 
    event.which : 
    (window.event.keyCode) ? 
    window.event.keyCode : 
    -1;
    if (keyCodeEntered == 8) {
        $(this).val(""); 
        return false;
    }
    return false;
   }