Search code examples
javascriptdatedevexpressautopostback

DevExpress DateEdit refresh


I got 2 DateEDit controls in my webform: StartDate and EndDate I want to validate that when EndDate changes, it won't be an earlier date than the StartDate. Also I want to validate that when the StartDate changes, the EndDate resets with StartDate's value + 1 day.

I managed to do this activating AutoPostBack, but doesn't seem so well... and without it the event DateChanged doesn't trigger.

       <td><dx:ASPxLabel ID="lbl_StarDate" runat="server" Text="Start Date:" Font-Bold="True" Visible="True">
            </dx:ASPxLabel></td>
       <td><dx:ASPxDateEdit ID="de_StartDate" runat="server" Height="19px" Width="240px"></dx:ASPxDateEdit></td>
     </tr>
     <tr>
       <td><dx:ASPxLabel ID="lbl_EndDate" runat="server" Text="End Date:" Font-Bold="True" Visible="True">
            </dx:ASPxLabel></td>
       <td><dx:ASPxDateEdit ID="de_EndDate" runat="server" Height="17px" Width="220px"></dx:ASPxDateEdit></td>

Can you please help me on this?


Solution

  • This can all be done in javascript. To trigger the javascript events, change your aspx to the following:

        <tr>
            <td>
                <dx:ASPxLabel ID="lbl_StarDate" runat="server" Text="Start Date:" Font-Bold="True"
                    Visible="True" />
            </td>
            <td>
                <dx:ASPxDateEdit ID="de_StartDate" ClientInstanceName="de_StartDate" runat="server"
                    Height="19px" Width="240px">
                    <ClientSideEvents ValueChanged="OnStartDateChanged" />
                </dx:ASPxDateEdit>
            </td>
        </tr>
        <tr>
            <td>
                <dx:ASPxLabel ID="lbl_EndDate" runat="server" Text="End Date:" Font-Bold="True" Visible="True" />
            </td>
            <td>
                <dx:ASPxDateEdit ID="de_EndDate" runat="server" Height="17px" Width="220px">
                    <ClientSideEvents ValueChanged="OnEndDateChanged" />
                </dx:ASPxDateEdit>
            </td>
        </tr>    
    

    Then handle the javascript in the respective methods:

    <script type="text/javascript">
    
        function OnStartDateChanged(s, e) {
           //code here
        }
    
        function OnEndDateChanged(s, e) {
            //code here
        }
    
    </script>