This is a migrated thread and some comments may be shown as answers.

Cannot clear the InvalidTextBoxValue of the RadDatePicker

5 Answers 248 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Remus
Top achievements
Rank 1
Remus asked on 26 Aug 2011, 11:46 AM
Hi!

I have a RadDatePicker that I want to reset its value on the server-side during a postback when the input is invalid. But it seems that once the property InvalidTextBoxValue is set, there is no way to clear that.

My test code looks something like this:

If Page.IsPostBack AndAlso Not String.IsNullOrEmpty(Me.RadDatePicker1.InvalidTextBoxValue) Then
    ' None of the following will help to show a new selected date in the date input -- the date input will fail to show anything
    Me.RadDatePicker1.Clear()
    Me.RadDatePicker1.SelectedDate = Now.Date
    Me.RadDatePicker1.DateInput.Clear()
    Me.RadDatePicker1.DateInput.SelectedDate = Now.Date
End If

I studied the source code in RadDateInput.cs and there are two variables used by InvalidTextBoxValue:

protected bool invalidDateStringFlag = false;
protected string invalidDateString;

It seems that those variables are never cleared anywhere, and once they are set there is no way to reset them, and those variables are affecting the logic of several properties and functions.

Shouldn't these variables be cleared when calling RadDatePicker.Clear or when setting RadDatePicker.SelectedDate, so that the RadDatePicker starts to behave "normally" again? Otherwise the RadDatePicker remains locked in its "invalid state" no matter what.

As an example, the following property of RadDateInput will never work properly again once the invalidDateStringFlag was set, since that flag is never cleared:

public virtual DateTime? SelectedDate
{
    get
    {
        if (String.IsNullOrEmpty(Text) || invalidDateStringFlag)
        {
            return null;
        }
        else
        {
            return DateTime.ParseExact(Text, hiddenFormat, DateTimeFormatInfo.InvariantInfo);
        }
    }
    set
    {
        if (value.HasValue)
        {
            if ((value > MaxDate) || (value < MinDate))
            {
                throw new ArgumentOutOfRangeException("SelectedDate", String.Format("Value of '{0}' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'.", value));
            }
            Text = value.Value.ToString(hiddenFormat, DateTimeFormatInfo.InvariantInfo);
        }
        else
        {
            Text = null;
        }
    }
}

Setting a new value for the SelectedDate will not change anything -- the returned value will always be Null in that state, no matter what it is changed server-side on the RadDatePicker!

I am using version Telerik.Web.UI.dll 2010.3.1109.35

So, the final question is how to put a new valid value into a RadDatePicker after the user has entered an invalid value? This should preferably be done server-side, since there are some other actions too that need to be taken following an invalid date input (not just resetting the date picker).

5 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 31 Aug 2011, 09:37 AM
Hi Remus,

Thank you for reporting this issue and also for sharing the discoveries that you made. We reviewed this and confirm that it is a bug in the RadDateInput. Thus it was not reported(or found) previously it is still not fixed in the current release. However we will fix it for the next release(service pack).

As appreciation for your feedback and detailed explanations about the found bug I award you with 500 Telerik Points.

Excuse us for the inconvenience that currently it is not able to set a valid value for your picker from server side after the user was entered an invalid one.

Regards,
Vasil
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Umesh
Top achievements
Rank 1
answered on 01 Mar 2013, 01:28 PM
I am suffering with this issue can you help me Telerik Team??

I am using Telerik version 2010.3.1109.20
0
Vasil
Telerik team
answered on 01 Mar 2013, 02:58 PM
Hi Umesh,

We have fixed the issue already, but for the old version that you are using there is no some sample workaround. However the property is defined as protected:
protected bool invalidDateStringFlag = false;
So you can inherit the RadDateInput, and expose public property to access this variable. And then to your your class in your page.

public class MyRadDateInput: RadDateInput
{
    public void ClearErrorFlag(){ base.invalidDateStringFlag = false; }
}

All the best,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jay
Top achievements
Rank 1
answered on 08 Mar 2013, 01:30 PM
Vasil,

I run into same issue as mention by previous user. Can you please elobarate your answer and provide some reference code?

Are you suggesting to create custom control using raddatetimepicker?

We appreciate your response...!!
0
Vasil
Telerik team
answered on 11 Mar 2013, 12:43 PM
Hi Jay,

I believe it is explained clear enough. If you are not aware how to inherit class in C# check these online resources:
http://msdn.microsoft.com/en-us/library/ms173149%28v=VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms173149.aspx

Kind regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Calendar
Asked by
Remus
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Umesh
Top achievements
Rank 1
Jay
Top achievements
Rank 1
Share this question
or