A newer version of this page is available. Switch to the current version.

ASPxClientDateEdit.ParseDate Event

Enables you to convert the value entered by an end user into the value that will be stored by the date editor.

Declaration

ParseDate: ASPxClientEvent<ASPxClientParseDateEventHandler<ASPxClientDateEdit>>

Event Data

The ParseDate event's data class is ASPxClientParseDateEventArgs. The following properties provide information specific to this event:

Property Description
date Gets or sets the edit value of the date editor.
handled Gets or sets a value specifying whether the event was handled.
value Gets the value entered into the date editor by an end user.

Remarks

Each time a date editor invokes validation (i.e. when an end user accepts the value entered or the editor is about to loose focus) the text displayed in the edit box is converted to the appropriate date/time type. The ParseDate event can be handled to implement custom conversions of values input on the client side. This can be used to override the default algorithm or to facilitate end users inputting values. For instance, end users could be allowed to enter 'today', and it would then be converted as appropriate.

The event's ASPxClientParseDateEventArgs.value property allows the currently entered value to be obtained. Set the ASPxClientParseDateEventArgs.date property to the value that should actually represent the editor's edit value. The ASPxClientParseDateEventArgs.handled property value must be set to true, to override the default conversion handling.

Examples

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