简体   繁体   English

停止 MaskedEditExtender 验证 asp.net 中的输入

[英]Stopping MaskedEditExtender from validating input in asp.net

I have an asp.net textbox and a MaskedEditExtender control attached to it.我有一个 asp.net 文本框和一个 MaskedEditExtender 控件。 The textbox is used for date input.文本框用于日期输入。 The MaskedEditExtender has MaskType="Date" Mask="99/99/9999". MaskedEditExtender 有 MaskType="Date" Mask="99/99/9999"。

When the form is submitted with an invalid date, the browser shows a Javascript error "... string was not recognized as a valid datetime".当表单以无效日期提交时,浏览器会显示 Javascript 错误“...字符串未被识别为有效日期时间”。

I know why the error shows up.我知道为什么会出现错误。 Is there a way to use the extender to just control what the user enters and not validate or convert the input?有没有办法使用扩展器来控制用户输入的内容而不验证或转换输入?

Stop the form from submitting with an invalid date.停止提交无效日期的表单。 Use a MaskedEditValidator使用 MaskedEditValidator

on the text box you and set up a keypress function.在文本框上你并设置一个按键功能。

Validate if the key pressed is a number String.fromCharCode(event.which) or event.keycode (ie or FF)验证按下的键是否为数字 String.fromCharCode(event.which) 或 event.keycode(即或 FF)

Then can check that the text box is contains valid code and format.然后可以检查文本框是否包含有效的代码和格式。

If invalid you can set to a default that is valid or just prevent the keypress by using preventDefault()如果无效,您可以设置为有效的默认值或使用 preventDefault() 阻止按键

if invalid format can disable the submit button also ....如果无效格式也可以禁用提交按钮....

Good luck祝你好运

不要将掩码类型指定为“日期”,这应该会阻止此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM