Compare dates in User control to parent control

2 posts, 0 answers
  1. nav100
    nav100 avatar
    48 posts
    Member since:
    Dec 2010

    Posted 10 May 2013 Link to this post

    I have datePicker control in User control and would like to compare the date with date Picker in  Parent Page date picker control value using Javascript. Could you please let me know?



    telerik:RadButton runat="server" Enabled="true" ID="btnSave" Text="Upload" OnClientClicked="OnClientClicked"






    Thank you.
  2. Viktor Tachev
    Viktor Tachev avatar
    1790 posts

    Posted 15 May 2013 Link to this post


    In order to get a reference to the RadDatePicker control you should use the following code:

    var rootDatePicker = $find('<%= DatePickerRoot.ClientID %>');

    The compare operation could be achieved as follows:

    function compareDates() {
                        var rootDatePicker = $find('<%= DatePickerRoot.ClientID %>');
                        var ucDatePicker = $find('<%= UserControl1.FindControl("DatePickerInUserControl").ClientID %>');
                        var rootDate = rootDatePicker.get_selectedDate();
                        var ucDate = ucDatePicker.get_selectedDate();
                        // compare dates here

    More information on RadDatePicker control's properties could be found in this article.

    If you would like to compare the values in the code-behind you could get an instance of the controls with FindControl method:


    The method would be similar to this

    protected void CompareButton_Click(object sender, EventArgs e)
            RadDatePicker userControlDatePicker = UserControl1.FindControl("DatePickerInUserControl") as RadDatePicker;
            RadDatePicker rootDatePicker = Page.FindControl("DatePickerRoot") as RadDatePicker;
            DateTime? rootDate = rootDatePicker.SelectedDate;
            DateTime? userControlDate = userControlDatePicker.SelectedDate;
            // compare dates here

    You could find attached a sample project illustrating both approaches - comparing the values using JavaScript and in the code behind.

    Let me know if this is helpful to you.

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