Brian Mains
Brian Mains

Reputation: 50728

Setting RadDatePicker Date Without Firing ValueChanged

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.

Upvotes: 2

Views: 7790

Answers (1)

Johan Lundqvist
Johan Lundqvist

Reputation: 36

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>

Upvotes: 2

Related Questions