This is a migrated thread and some comments may be shown as answers.

Compare dates in User control to parent control

1 Answer 55 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
nav100
Top achievements
Rank 1
nav100 asked on 10 May 2013, 08:47 PM
Hi,
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.

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 15 May 2013, 11:26 AM
Hello,

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:

Page.FindControl("DatePickerRoot")

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.

Greetings,
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.
Tags
Calendar
Asked by
nav100
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or