Skip to main content
A newer version of this page is available. .

ASPxClientParseDateEventArgs.date Property

Gets or sets the edit value of the date editor.

Declaration

date: Date

Property Value

Type Description
Date

A date/time value representing the edit value of the date editor.

Remarks

The date property represents the current edit value.

In order to convert the string entered by an end user into an appropriate date, analyze the value of the ASPxClientParseDateEventArgs.value property and set the date property to the corresponding date/time value that should actually be assigned to the date editor. Note that the ASPxClientParseDateEventArgs.handled property’s value must be set to true, to override default conversion handling.

Example

This example demonstrates how the ParseDate event can be handled to resolve user input strings entered into the ASPxDateEdit.

After you type a predefined date constant (such as "today") or a simple expression (such as "today + 2") and press ENTER, the relevant date is automatically calculated and set to the editor.

<script type="text/javascript" language="javascript">

        function SmartParseDate(value){
            var dayDeltas = {
                "TODAY": 0, 
                "TOMMOROW": 1,
                "YESTERDAY": -1,
                "NOW": 0
            };
            var ret = null;

            if(_aspxIsExists(value)){
                var text = value.replace(/ /g,"");
                text = text.toUpperCase();

                for(var day in dayDeltas){
                    if(text.substr(0,day.length) == day){
                        text = text.substr(day.length);

                        var dayCount = parseInt(text);
                        if(isNaN(dayCount))
                            dayCount = 0;

                        var dateResult = new Date();
                        if(day != "NOW")
                            dateResult.setHours(0,0,0,0);
                        dateResult.setDate(dateResult.getDate() + dayCount + dayDeltas[day])
                        if(!isNaN(dateResult))
                            ret = dateResult;
                    }
                }
            }
            return ret;
        }

        function OnParseDate(editor, args){
            var date = SmartParseDate(args.value);
            if (date != null) {
                args.date = date;
                args.handled = true;
            }
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dxe:ASPxLabel ID="ASPxLabel1" runat="server" AssociatedControlID="ASPxDateEdit1"
            Text="Type a specific predefined word or expression (such as 'today + 1') within the date editor and press ENTER.">
        </dxe:ASPxLabel><dxe:aspxdateedit id="ASPxDateEdit1" runat="server" EditFormat="DateTime">
            <ClientSideEvents ParseDate="function (s, e){
                OnParseDate(s, e);
            } ">
            </ClientSideEvents>
    </dxe:aspxdateedit>
See Also