How to restrict text entry on Kendo Angular Date Picker? - c#

Kendo's Angular Date Picker, restricts the date selection using [min] and [max] to select date from the UI. However, for text entry (user types in the date instead of selecting from the datepicker) user is restricted to enter months above 12 and dates above 30/31 accordingly. But, I need to restict user to type the year as well. Suppose if user types 1996 and my max year is 1995, the date year should change to 1995.

You can make one function which triggers when date is changed, this function should check if your requirements are satisfied with newly entered date OR it should revert back to last value . The Benefit of this approach is that user still can type the values but still it should be inside your validation range.

Related

C# Datetimepicker Way to Stop Validation

I have a datetimepicker with format dd.MM.yyyy when i have, for example, date 14.02.2011, save it and then want to enter 31.12.2011 then datetimepicker validator doesnt allow me to enter 31 because of month 02 inside,so it set automatically 29 in the datetimepicker.
In this case, i have to go to change a month and then back to change a day, is there a way to switch off this validation?
You have set a Value (DateTime) for the control and are now trying to change its elements one at a time, such that an intermediate value is invalid.
Assuming you are talking about the .Net Framework class (System.Windows.Forms), before capture (re)starts, you can use the ResetText() method or set the Value or Text property to an appropriate starting value for your use case. Otherwise, instead of allowing separate editing of Value.Day, .Month and .Year, capture the full text representation of the date and update the control's Text property afterwards.

Xaml DatePicker default and earliest date available for selection settings in C#

I have couple of datepicker implemented in Xaml .
- After user picks certain dates, a simple logic finds the earliest of the two dates. Also, it is not necessary for user to pick both dates.
I noticed that the "default" datepicker value if user does not pick any date is 1/1/0001.
Assuming the user picks the second date as 1/1/2017, the earliest of the two dates would always be 1/1/0001 which is not desired. In such scenario, the minimum date should be 1/1/2017.
what is the logic to neglect default date of 1/1/0001
There is a property MinYear which can be set to minimum year accepted which in your case obviously should be 2017. This will solve the problem by automatically limiting range of available values to be lower bounded by 2017-01-01 - this for UWP DatePicker.
In WPF DatePicker there is a DisplayDateStart property which can be set to minimum date available in drop down calendar which can be chosen by user. Similar property DisplayDateEnd is used for setting highest date which can be displayed in DatePicker. DatePicker.SelectedDateChanged is a very useful event which when wired up will capture changes to the dates on all instances of DatePickers and this can be used to create relations between them i.e. to enforce selection of the valid period which starts from date selected on DatePicker 1 and ends on date selected in DatePicker 2 by setting DisplayDateStart on picker 2 to date selected on picker 1 in event handler. This all together provides very high level of flexibility in controlling user input via DatePicker class.

how to retrieve the date via session variables?

So here is the scenario:
Page1.aspx:
I created a read-only textbox, followed by a simple calendar.
On selecting the date, the long date appears in the textbox.
Page1.aspx.cs:
created a session and stored the date in it.
Page2.aspx:
Created a label field to house the date value.
Page2.aspx.cs:
now i want to rerieve the date value into the label.
Problem1: on selecting the date from the calendar, the page refreshes and then the data is reflected into the textbox
Problem2: can't convert and store the date values into the label.
Please help.
DataType variable=(Datatype)Session["SessionVariable"];
Retrieve like this by typecasting the session value to its appropriate type.
For Example:
Date variable=(Date)Session["date"];
I'm not sure I understand Problem1 correctly, but it seems that you would like the page to display the date in the textbox without reloading. In that case, take a look at jQuery UI's Datepicker: http://jqueryui.com/datepicker/
As to Problem2, you probably can fix that by creating a new DateTime object with the Parse method. The other way around (from DateTime to string) can be done with the ToString method.

Bind drop down list to calendar with conditions

I'm new to ASP.NET and C# and I'm having trouble completing a project. I'm trying to create a page where a user can select an item from a drop-down list, which contains four options. Each option is tied to specific days and times of the week. I'm trying to make it so when a user selects an option where the specified days are Monday, Wednesday, and Friday, it makes it so the corresponding calendar only allows for Monday, Wednesday, or Friday to be selected.
No way ofdoing this the way you want to. Check out some javascript calendar pickers that can be configured to only allow certain months and use that on front end.
Perhaps you can store the current selection and then in the on select event if the event is one you don't want the user to select then reselect the stored (previous) selection?

Configuring the Date Popup on the WPF DatePicker Control

I have a date picker control that I use for a data collection application. It is using MvvM data binding. When going through a list of dates (see fig1) it will populate the date picker correctly. Whenever I hit new, the date pickers are nulled out. When I pull up the popup, it selects the month and year from the previous date that was set to. (fig 2) Is there anyway to default the pop up show the current month in the current year?
Note : I would like to keep the selected date to null on a new entry to force some validation.
Fig 1
Fig 2
The following image is to show what happens when I set the DisplayDateStart.
(original answer was horribly wrong, sorry about that)
Okay, lets try this again.
Have you tried setting the fallback to today's date?
SelectedDate="{Binding TehDate, FallbackValue={x:Static sys:DateTime.Now}}"

Categories