Catch exception on RadDateTimePicker PreRender

2 posts, 0 answers
  1. Craig Wallace
    Craig Wallace avatar
    118 posts
    Member since:
    Jan 2005

    Posted 08 Mar 2012 Link to this post


    I have noticed that is possible in code to set the MinDate as greater than the MaxDate on the RadDateTimePicker.  When the aspx is then rendered, an ArgumentOutOfRangeException is thrown.  It is only thrown on the OnPreRender event of the control, and no opportunity is given to catch and handle it without overriding OnPreRender for the control.

    Can I ask that the control be changed to make it possible for such exceptions to be caught when the MinDate and MaxDate properties are set?  This seems a much more sensible time to throw such an exception, as it seems quite unusual to have to override prerender to prevent a control from blowing up an entire aspx page?

  2. Vasil
    Vasil avatar
    1642 posts

    Posted 12 Mar 2012 Link to this post

    Hello Craig,

    I see your point in there. And actually we are able to change the behavior and to throw this exceptions in the setters of the properties.

    However I see another problem that will occurs in here. And I am not sure if the change will be for good or not. Here is the scenario:

    By default the MaxDate is 12/31/2099 and the MinDate is 1/1/1980.
    So if the user dynamically want to change the possible range to 1/1/1900 to 1/1/1950. He could write:
    RadDatePicker1.MaxDate = new DateTime(1950, 1, 1);
    RadDatePicker1.MinDate = new DateTime(1900, 1, 1);
    And he will get an exception when setting the MaxDate, because MinDate is still 1/1/1980 when he try to change the MaxDate. Which indeed could be very common scenario when if user sets values that are greater than 2099 even if he set the MinDate first:
    RadDatePicker1.MinDate = new DateTime(2100, 1, 1); 
    RadDatePicker1.MaxDate = new DateTime(2200, 1, 1);

    However, if the checking is made on PreRender the both properties will be set correctly and no exception will be thrown. So making such change could break already working code for many people.

    I would ask the community here which approach is better for your? I would also appreciate If you could think of any alternatives as well.

    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