Can I create Date entry control with date separator for classic ASP

∥☆過路亽.° 提交于 2019-12-08 08:54:21

问题


I was using a calendar control for entry of date in a classic-ASP application. But calendar control is not keyboard friendly and take more time for data entry. So later I added a simple text box with date validation. It works fine. However, the user need to put the date separator also. I wish to put a date entry field that comes with a pre-configured date format and separator, so that the user simply type on the numbers and the field cause a validation as well.

How can I achieve this?


回答1:


Just use jQuery/javascript to mask the date text field. It will automatically format the date as the user enters the values. Also forces correct validation as it works.

for example jQuery plugins search for :

jquery date mask: http://digitalbush.com/projects/masked-input-plugin/




回答2:


You can always put three text boxes with the separator as text (as I do in an old ASP classic site)

You need to separate the date in the response and then join it using DateSerial when posted.




回答3:


When we've created something similar in the past we've allowed the user to enter a date into a textbox in a couple of different ways:

  • DDMMYYYY
  • D/M/YYYY
  • 0 (for today)

When the form is submitted we had a simple ASP function to convert DDMMYYYY into DD/MM/YYYY (date string must be 8 characters though because the assumption was 2 digits for DD, insert the separator, 2 for MM, etc.) and check this was a valid date, and an if formdate = 0 then formdate=now() rule.

You need to add some JavaScript validation on the form too though. On the textbox add an onblur event to check for the same things - either 8 digits entered, or a valid date, or a 0 - otherwise alert the user. (I would do this in jQuery if we were redoing it today)

You can get quite helpful with the Javascript "validation" to speed up data-entry if you wanted to, for example if a lot of dates being entered are yesterday or tomorrow allow a -1 or +1, or if data entry is always for the current month but a different day, allow the user to just enter a number - 15 and the Javascript/jQuery converts the string to 15/03/2011.




回答4:


With HTML 5...textMode="Date"

<asp:TextBox ID="TextBoxDate" 
       runat="server"
       CssClass="form-control" Width="561px"
       TextMode="Date"> 
</asp:TextBox>


来源:https://stackoverflow.com/questions/5482064/can-i-create-date-entry-control-with-date-separator-for-classic-asp

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