This is a migrated thread and some comments may be shown as answers.

RadDateInput Parsing for Month-Year Input

1 Answer 54 Views
Input
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 11 Mar 2014, 05:05 PM
We are using the RadDateInput for drivers license expiration date. Some users want to enter only the month and year such as 02/2014 but the control parses this to 3/2/2014 rather than 2/1/2014. Is there a workaround for this behavior?

Thanks

Charles

1 Answer, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 11 Mar 2014, 09:26 PM
Hi,
When you enter two numbers in the RadDateInput control (one of which is the year), it always assumes that one number is the year and the other one is the day (and takes the current month).You can try with the below implementation to resolve this issue

HTML Mark up:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="EmptyWebApp.WebForm2" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function DateInput1ValueChanging(sender, args) {
            var newv = args.get_newValue();
            var newvArray = newv.split("/");
            if (newvArray.length == 2) {
                // if the date format is dd/MM/yyyy, the 01 string should be appended in the beginning, not in the middle
                args.set_newValue(newvArray[0] + "/01/" + newvArray[1]);
            }
        }
  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <telerik:RadDateInput ID="RadDateInput1" runat="server" DateFormat="MM/dd/yyyy" DisplayDateFormat="MM/dd/yyyy">
            <ClientEvents OnValueChanging="DateInput1ValueChanging" />
        </telerik:RadDateInput>
    </div>
    </form>
</body>
</html>

C#:
protected void Button1_Click(object sender, EventArgs e)
       {
           //Get the Value
           string value = RadDateInput1.Text;
       }

Source URL
Tags
Input
Asked by
Charles
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
Share this question
or