RadDateTimePicker Problem

11 posts, 0 answers
  1. Vasile Grafu
    Vasile Grafu avatar
    4 posts
    Member since:
    Oct 2009

    Posted 18 Nov 2009 Link to this post

    Hi,

    I have a problem with RadDateTimePicker ASP.NET control.

    I would like to have a RadDateTimePicker with DataInput-ReadOnly="true".
    Lets suppose initially there a no data selected. Afetr I will select I want to reset it (to empty the DataInput).
    How can I do that without some JavaScript code ... othere are some property?

    Another problem bellow.

    I need the next behaviour:
    1. My aplication contains: Domain Tier, ControllersTier, App Logic Tier, Presenters Tier, UI Tier.
    I insert PresenterTier for reusing later in another UI the same logic ... For me the UI is just a mapping way between User and App Logic.

    2. I am not interested to do any kind of validation on UI side. So my validation are made in presenters. So I need to pass to the server all values (either wrong which the user enters .. I will validate in presenter and I will fire a message).

    3. The RadDateTimePicker  when has a wrong data will pass in PostBack null value.  I do not want that.
    I am interested to get the wrong value (not NULL) when the user input has introduced into UI (because validation I will make in Presenter)
    So i need to deactivate the validation mechanism for RadDateTimePicker ... because the RadDateTimePicker on the client side when somehting is not good with what the user enter then will pass null on postback. This is not good.

    Thank you.
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 23 Nov 2009 Link to this post

    Hello Vasile,

    I am afraid that at current implementation of RadDatePicker/RadDateTimePicker there is no way of posting back invalid Date to server. This is due to the reason that picker control tries to parse value posted from client to DateTime and this might break the control.

    All the best,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vasile Grafu
    Vasile Grafu avatar
    4 posts
    Member since:
    Oct 2009

    Posted 23 Nov 2009 Link to this post

    Well, thank you for your answer.

    The other issue at you should think about this:

    I have in database 2 columns into a table: start date, expiration date. Expiration date could be null in which case will be treated like infinite.
    So we have an open interval (start date, expiration date) or (star date , null) ->which means infinite.

    I think will be best if you can insert into RadDateTimePicke a flag or something ... that we know when the user get null on server side means that he doesnt set the value.

    The problem is that in some cases when the user input a wrong value to the server is passed null ... which is bad :)

    Of curse i have already solved that ... through other ways ... but it will be very elegant to do that in the future.

    Thanks you for your support.

    I write that because I am aware that trough this we can get a better features in the future from you.
  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 26 Nov 2009 Link to this post

    Hello Vasile,

    I understand your concerns regarding RadDatePicker, but you must have in mind that RadDatePicker expects DateTime as value and only DateTime is valid value. If the value is not valid it must be null.

    However I will forward your suggestions to our development department for further consideration.

    Sincerely yours,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Scott Davis
    Scott Davis avatar
    10 posts
    Member since:
    Apr 2010

    Posted 11 Feb 2011 Link to this post

    I also have an issue with validation on the RadDatePicker that seems to be related to this, so I thought it appropriate to tag it onto this post.

    I am using the RadDatePicker within a fairly complex application that utilizes WebUserControls extensively.  The DateTimePicker may be used for input of several date fields on a particular form.  Many of the input fields on these forms require validation of some sort and I am using a ValidationSummary control to summarize all of the errors to the user when they click the "Save" button.  I am using a RequiredFieldValidator on the RadDatePicker which works fine.  If the user were to input an invalid date into the RadDatePicker the user does see the invalid date style of the RadDatePicker that produced client side.  However, if the user does not notice this and clicks the Save button causing a postback, the invalid date style is wiped out, whatever they typed into the RadDatePicker is wiped out and no message is displayed in the ValidationSummary.

    I have always used the good practice of checking validation on the server side as well by calling Page.Validate() and then checking the Page.IsValid property.  However, when the user enters an invalid value into the RadDatePicker, doing this does not result in the Page.IsValid property returning false.  So the server side has no idea that something invalid was entered.

    I have tried attaching a CompareValidator to the RadDatePicker, but this again does no good on the server side presumably because the value being checked by the validator is NULL and not the invalid value that was entered by the user.

    Is there some way that I can accomplish server side validation with the RadDatePicker?
  7. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 16 Feb 2011 Link to this post

    Hello Scott,

    I am afraid that RadDatePicker does not support this scenario. When invalid value is typed inside RadDateInput it attempts to correct the value or leave it as is.
    If the value is not valid DateTime on postback it will be cleared.

    Regards,
    Nikolay
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  8. Scott Davis
    Scott Davis avatar
    10 posts
    Member since:
    Apr 2010

    Posted 16 Feb 2011 Link to this post

    Thank you for the reply and I do understand the limitation now.

    Is there any way that I can make the RadDatePicker continue to display the invalid entry style after a postback?  I understand that I won't be able to validate server side, but I would like the user to get some type of visual indication that the date they entered was incorrect if they enter an invalid value and click the Save button (which causes a postback).
  9. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 22 Feb 2011 Link to this post

    Hello Scott,

    On server side you can actually access the invalid value via InvalidTextBoxValue property of the picker.

    On client side you can force invalid style by executing the code bellow:
    var input = $find("Picker").get_dateInput();
    input._invalidate();
    input.updateCssClass();

    Regards,
    Nikolay
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  10. Scott Davis
    Scott Davis avatar
    10 posts
    Member since:
    Apr 2010

    Posted 22 Feb 2011 Link to this post

    Thank you for the response.  I was able to use a CustomValidator and check the InvalidTextBoxValue in the ServerValidate method to get around the issue.  If the InvalidTextBoxValue contained any type of value it meant the user entered an invalid date and thus I set the IsValid property of the CustomValidator to false.  Seems to work fine.
  11. Piyushkumar
    Piyushkumar avatar
    25 posts
    Member since:
    Nov 2010

    Posted 26 Aug 2013 Link to this post

    Hi,

    I am facing the same problem.

    Is there a way to retain the invalid date within the textbox after a post-back ?

    Thanks,
    Piyush
  12. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Aug 2013 Link to this post

    Hi Piyushkumar,

    Please check the following code I tried to achieve your scenario. Also please note that the default behavior of RadDateTimePicker is that the control automatically attempts to correct the invalid value typed inside the textbox or leave it as it is. If the value is not a valid DateTime, on postback the value as well as the invalid style will be cleared.

    ASPX:
    <telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server">
    </telerik:RadDateTimePicker>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <br />
    <telerik:RadButton ID="RadButton1" runat="server" Text="PostBack">
    </telerik:RadButton>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (RadDateTimePicker1.InvalidTextBoxValue.Length != 0)
            {
                HiddenField1.Value = RadDateTimePicker1.InvalidTextBoxValue;
            }
            else
            {
                HiddenField1.Value = null;
            }
        }
    }

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var hiddenfield = document.getElementById("HiddenField1").value;
            if (hiddenfield.length != 0) {
                var input = $find("RadDateTimePicker1").get_dateInput();
                input.set_textBoxValue(hiddenfield);
                input._invalidate();
                input.updateCssClass();
            }
        }
    </script>

    Thanks,
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017