开发者

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

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 开发者_如何学Pythonsimple 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?


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/


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

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

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


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.


With HTML 5...textMode="Date"

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜