RadTimePicker FindControl problem

4 posts, 0 answers
  1. Olga
    Olga avatar
    20 posts
    Member since:
    Dec 2010

    Posted 22 Feb 2011 Link to this post

    Hi,

    I have the following line of code
    RadTimePicker startTime = this.NamingContainer.FindControl(StartTimeControlID) as RadTimePicker;

    It worked fine when our application was using Classic controls.  Now that we upgraded to ASP.NET AJAX, startTime is always null.  It is as if it can no longer find the control.  StartTimeControlID is not null and I know that the control is there in "this".  What am I missing?

    Thanks,
    Olga
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 24 Feb 2011 Link to this post

    Hello Olga,

    Could you please post the code that resides in this event? I would also appreciate if you paste your markup in this thread - this way I will be able to provide straight-to-the-point answer.

    Regards,
    Daniel
    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!
  3. Olga
    Olga avatar
    20 posts
    Member since:
    Dec 2010

    Posted 24 Feb 2011 Link to this post

    Hi Daniel,

    Here is the entire C# code of the control this snippet resides in. 

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
      
    using Telerik.WebControls;
    using System.ComponentModel;
    using Fox.Fbc.Rds.RdsWeb.Data;
      
    namespace Fox.Fbc.Rds.RdsWeb.WebControls
    {
        /// <summary>
        /// ValidTimeRangeValidator is used to check that start time and end time happen in chronological order
        /// given the broadcasting day's start time of 6AM
        /// </summary>
        [ToolboxData("<{0}:ValidTimeRangeValidator runat=server ErrorMessage=\"End time should be past start time. Note that Broadcast Day starts at 6:00 AM. To select the whole day set both start and end times to 6:00 AM\"></{0}:ValidTimeRangeValidator>")]
        public class ValidTimeRangeValidator : BaseValidator
        {
            public static readonly TimeSpan BroadcastDayStart = TimeSpan.FromHours(6);
      
            [TypeConverter(typeof(ValidatedControlConverter)), IDReferenceProperty, Themeable(false), DefaultValue("")]
            public string StartTimeControlID
            {
                get
                {
                    object obj2 = this.ViewState["StartTimeControlID"];
                    if (obj2 != null)
                    {
                        return (string)obj2;
                    }
                    return string.Empty;
                }
                set
                {
                    this.ViewState["StartTimeControlID"] = value;
                }
            }
      
            [TypeConverter(typeof(ValidatedControlConverter)), IDReferenceProperty, Themeable(false), DefaultValue("")]
            public string EndTimeControlID
            {
                get
                {
                    object obj2 = this.ViewState["EndTimeControlID"];
                    if (obj2 != null)
                    {
                        return (string)obj2;
                    }
                    return string.Empty;
                }
                set
                {
                    this.ViewState["EndTimeControlID"] = value;
                }
            }
      
            protected override bool ControlPropertiesValid()
            {
                if (String.IsNullOrEmpty(StartTimeControlID))
                    throw new HttpException("StartTimeControlID cannot be empty");
                if (String.IsNullOrEmpty(EndTimeControlID))
                    throw new HttpException("EndTimeControlID cannot be empty");
      
                RadTimePicker startTime = this.NamingContainer.FindControl(StartTimeControlID) as RadTimePicker;
                RadTimePicker endTime = this.NamingContainer.FindControl(EndTimeControlID) as RadTimePicker;
                if (startTime == null)
                    throw new HttpException(String.Format("Validator control {0} cannot be found", StartTimeControlID));
                if (endTime == null)
                    throw new HttpException(String.Format("Validator control {1} cannot be found", EndTimeControlID));
      
                return true;
            }
              
        }
    }

    Thanks,
    Olga
  4. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 02 Mar 2011 Link to this post

    Hello Olga,

    Thanks for the sample code. This will work properly provided that your custom validator resides in the same naming container as the RadTimePicker control.
    Please post the markup that surrounds the custom validator and I will debug your code locally.

    Best regards,
    Daniel
    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!
Back to Top