This is a migrated thread and some comments may be shown as answers.
RadTimePicker FindControl problem
3 Answers 26 Views
This is a migrated thread and some comments may be shown as answers.
Olga
Top achievements
Rank 1
Olga asked on 23 Feb 2011, 04:50 AM
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

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Feb 2011, 10:44 PM
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!
0
Olga
Top achievements
Rank 1
answered on 25 Feb 2011, 12:08 AM
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
0
Daniel
Telerik team
answered on 02 Mar 2011, 04:52 PM
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!
Asked by
Olga
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Olga
Top achievements
Rank 1
Share this question
or