Cannot clear the InvalidTextBoxValue of the RadDatePicker

6 posts, 1 answers
  1. Remus
    Remus avatar
    2 posts
    Member since:
    Feb 2010

    Posted 26 Aug 2011 Link to this post

    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).
  2. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 31 Aug 2011 Link to this post

    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 >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Umesh
    Umesh avatar
    1 posts
    Member since:
    Jan 2012

    Posted 01 Mar 2013 Link to this post

    I am suffering with this issue can you help me Telerik Team??

    I am using Telerik version 2010.3.1109.20
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 01 Mar 2013 Link to this post

    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.
  6. Jay
    Jay avatar
    8 posts
    Member since:
    Oct 2010

    Posted 08 Mar 2013 Link to this post

    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...!!
  7. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 11 Mar 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017