Setting RadDatePicker Date Without Firing ValueChanged

7.7k views Asked by At

Using the client API, I'd like to be able to do this:

picker.set_selectedDate(new Date());

Without the valueChanged event handler firing, is there another way in the API to do this? Again this is all client-side JavaScript.

Thanks.

1

There are 1 answers

1
Johan Lundqvist On BEST ANSWER

You can remove the event handler from the datepicker and then set the date, like this:

 var datePicker = $find("<%= RadDatePicker1.ClientID %>");            
 datePicker.remove_dateSelected(DateSelected);
 datePicker.set_selectedDate(new Date());

this will prevent the event from being fired, if you need it you can add it again after. The DateSelected is the name of the event that you have set on the control, see below for a small example

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="SM" runat="server"></asp:ScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
    function pageLoad() {
        var datePicker = $find("<%= RadDatePicker1.ClientID %>");            
        datePicker.remove_dateSelected(DateSelected);
        datePicker.set_selectedDate(new Date());
    }

    function DateSelected(sender, e) {
        alert(sender);
    }
</script>
</telerik:RadCodeBlock>
<div>
     <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
        <ClientEvents OnDateSelected="DateSelected" />                       
     </telerik:RadDatePicker>
</div>
</form>