RadDatePicker DateChanged issue

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

    Posted 03 May 2013 Link to this post

    I have RadDatePicker control with SelectedDateChanged event. When I change the Date the event fires with Confirm window. When I click on 'Cancel' button RadDatePicker1_SelectedDateChanged invokes again and it displays Confirm window twice. When I click on 'OK' button it works fine. What could be the problem? Thanks for any suggestions. I am using 2010 Q3 controls.

          <telerik:RadDatePicker ID="RadDatePicker1" runat="server" AutoPostBack="true" OnSelectedDateChanged="RadDatePicker1_SelectedDateChanged" >
        protected void RadDatePicker1_SelectedDateChanged(object sender, EventArgs e)
        string radalertscript = "<script language='javascript'>function f(){ radconfirm('Are you sure?', confirmChange, 400, 100) ; Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
                             Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert33", radalertscript);

    Here is Javascript function

        function confirmChange(args) {
            if (args) {
                __doPostBack("<%= hiddenButton1.UniqueID %>", "");
        { var picker = $find("<%= rdpIndictment.ClientID %>");

          var hdval = document.getElementById('hiddenControlOldValue').value;

          picker.set_selectedDate(new Date(hdval));
    It looks like the problem is setting old value to Date Picker when 'Cancel' button clicked. Is there are any way I can Cancel Date Picker new selected value when 'Cancel' button clicked?



  2. Keith
    Keith avatar
    94 posts
    Member since:
    Jun 2012

    Posted 04 May 2013 Link to this post

    You are correct. The issue is that clicking the cancel button changes the value back to the original value, thus firing the event twice.

    There are a couple of ways to handle this, but setting a flag seems pretty simple and straightforward.

    <!-- Note: AutoPostBack may not be needed -->
    telerik:RadDatePicker ID="RadDatePicker1" runat="server" AutoPostBack="false">
        <DateInput runat="server">
            <ClientEvents OnValueChanged="confirmChange" />

    <script type="text/javascript" language="javascript">
        //Save old date value
        var hdval;
        //Set the flag to false
        var resetFlag = false;
        function valChanged(sender, args) {
            //No need to find a hidden control, args contains _oldValue and will suit our needs
            var hdval = args._oldValue;
            //If we are not resetting the control then fire the confirm dialog
            if (!resetFlag)
                radconfirm('Are you sure?', confirmChangeCallback, 400, 100);
            //Clear the reset flag
            resetFlag = false;
        function confirmChangeCallback(args) {
            //Get the control to reset
            var picker = $find("<%= rdpIndictment.ClientID %>");
            if (args) {
                //Do stuff here on OK
                __doPostBack("<%= hiddenButton1.UniqueID %>", "");
            } else {
                //Do stuff here on cancel
                //Tell the OnValueChanged handler to ignore the next value change
                resetFlag = true;
                //Reset the date to the saved value
                picker.set_selectedDate(new Date(hdval));

    Is that what you were looking for?
Back to Top