Dirty Check with RadComboBox and DatePicker

2 posts, 0 answers
  1. Divyang
    Divyang avatar
    13 posts
    Member since:
    Dec 2010

    Posted 20 Jul 2011 Link to this post


         if any value of control change a flaf "dirty" is set to true else it is false. When user leave that page and if dirty flag is true. He is asked to save records or close window without saving.

    We are using below script to find dirty flag for all the controls.

        var isDirty = false;
        var resetControls = ""// should be in , separated with # in ids
    	var msg = 'You haven\'t saved your changes.\n Do you want to save changes ?';
    	$(document).ready(function () {
    	    alert($(".section :hidden").length);
    	    $(":submit,:reset ").click(function () {
    	        isDirty = false;
    	        alert("Dirty flag reset");
    	    $(':input').change(function () {
    	        if (!isDirty) {
    	            alert("Dirty flag set")
    	            isDirty = true;
    	    window.onbeforeunload = function () {
    	        if (isDirty) {
    	            return msg;

    Above script is working fine with all input controls except hidden fields. Specifically RadComboBox and RadDatePicker are using hidden fields to post data.

    Could you please provide solution so that we can check dirty flag with rad controls ?
  2. Kalina
    Kalina avatar
    918 posts

    Posted 26 Jul 2011 Link to this post

    Hello Divyang,

    You can try attaching the "change" event handler at RadComboBox input in this manner:
    $(document).ready(function() {
        var isDirty = false;
        $(".rcbInput").change(function() {
            if (!isDirty) {
                alert("Dirty flag set")
                isDirty = true;

    However I am not sure that this approach is applicable at the RadDataPicker control – but you can easily set the isDirty variable by handling the OnDateSelected event:
    <telerik:RadDatePicker ID="RadDatePicker" runat="server"
        Width="140px" MinDate="01/01/1000"
                <telerik:RadCalendarDay Repeatable="Today" />
        <ClientEvents OnDateSelected="DateSelected" />

    function DateSelected(sender, eventArgs) {
        // your code here...

    All the best,
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top