I have a TextBox where the user is able to enter in their preferred date format pattern (e.g. dd/M/yyyy, yy-dd-mm).
How can I validate this Textbox? I could do it on the server-side by setting the Text property of this Textbox to cultureInfo.DateTimeFormat.ShortDatePattern and then catching the thrown exception, but I want to do this on the client-side using ASP.NET validators (a CompareValidator or RegularExpressionValidator).
This is a very difficult problem to search for as all that comes up are date format validation problems.
Related
Is there a way to modify the WPF DatePicker so that the user can enter non dates (e.g period codes such as 1Y) in addition to dates?
Basically I'm looking for a text entry field that can take any string (or optionally a string that matches a custom validation rule) that has a calendar icon next to it, which when used will paste the selected date into that text field...
I have a text box in my content page of asp.net webapplication. I masked the text box with maskededitextender with date format dd/MM/yyyy. I use custom validator to validate the text box. While entering wrong date format in text box like MM/dd/yyyy(12/23/2011) it will throw validation message "Incorrect date format". During this time it disables all other links in Master page.
How to overcome this problem. Can anyone help me with this?
Thanks.,
First of all tell us that how are you validating the maskededitextender..
If your page will not pass validation then you can not post back the
page or in other words all links on the page will be disabled/ fail to
create post back.
Check this SO thread for validation setttings:
how to validate MaskedEditExtender control for MM/dd/yyyy format?
I have one textbox in asp.net application. I have used MaskedEditExtender and CalendarExtender. I use the date format yyyy-mm-dd. When i type the date in textbox the typed date displayed in the textbox. But when i select date from calender the date is not displayed in the textbox. Only the masked format "_--_" is displayed. Can anyone able to help me to solve the problem. Thank you..
Make sure your CalendarExtender has the runat="server", Format="yyyy-mm-dd" and TargetControlID="YourTextBox" properties set.
Have you considered using JQuery? It has a lovely Calendar control (datePicker) which is part of the JQuery.UI library. Much more useful than the ASP.AjaxToolkit stuff!
I ve two aspCalendar controls on the website. I would like to perform validation (date from Calendar2 should be greater then date from Calendar 1).
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator"
ControlToValidate="Calendar2"
Operator="GreaterThanEqual"
Type="Date"
ControlToCompare="Calendar1"
/>
There are a lot examples of validation but with ControlToValidate as textBox or label, What about more complex Controls, is there any way I can tell which property from that control has to be used?
Maybe Client side validation ? But how to do this ?
Thanks for help
I would recommend using a customvalidator, which gives you complete control over the way the validation occurs. The control to validate may not accept the calendar; however, you can point it to a textbox, but behind the scenes in the servervalidate function validate your calendars, and so that is a workaround to making the validators work with controls like the calendar.
You could use client validation, but it depends on what you are trying to validate and how easy it would be; there is a lot of markup with the calendar control, so that might be hard...
HTH.
I haev an object with a DateTime property. I want to map the time to a textbox (thus want the user enter the time, it's directly reverberated to my property).
However I just want to display the time. How can I say this (ie the format should be something like hh:mm to be correct).
Less specifcly how can I format the text "sent" to the object and the other way too ?
Thx
You can specify "HH:mm" as the binding's FormatString
If you need more complex formatting than what a format string can provide, you can handle the Format event of the binding, which enables you to provide your own formatting logic