A RadDatePicker Bug?

2 posts, 0 answers
  1. Charles
    Charles avatar
    7 posts
    Member since:
    Jun 2013

    Posted 31 Jan 2014 Link to this post

    Hi,

    If I cleared the data in RadDatePicker and disabled it from client side. the backend would not get the null value and the disabled status after the page was posted back. Is this a bug?

    If I didn't disable the control after cleared the date on client, the backend will get null value.

    Here are the code.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
     
    <!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>
       <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
       <form id="form1" runat="server">
       <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
          <Scripts>
             <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
             <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
             <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
          </Scripts>
       </telerik:RadScriptManager>
       <script type="text/javascript">
          //Put your JavaScript code here.
       </script>
       <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       </telerik:RadAjaxManager>
       <div>
          <telerik:RadDatePicker ID="RadDatePicker1" runat="server" />
          <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
          <br />
          <br />
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
          <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
          <script type="text/javascript">
             $(document).ready(function ()
             {
                //var date = new Date("2000-01-01");
                var datepicker = $find("<%= RadDatePicker1.ClientID %>");
     
                datepicker.clear();
                //datepicker.set_selectedDate(null);
                datepicker.set_enabled(false);
             });
     
          </script>
       </div>
       </form>
    </body>
    </html>

    using System;
    using System.Web.UI;
     
     
    public partial class Default : System.Web.UI.Page
    {
       protected void Page_Load (object sender, EventArgs e)
       {
          if (!Page.IsPostBack)
          {
             RadDatePicker1.SelectedDate = DateTime.Now;
          }
       }
     
       protected void Button1_Click (object sender, EventArgs e)
       {
          if (RadDatePicker1.SelectedDate == null)
          {
             TextBox1.Text = "null";
          }
          else
          {
             TextBox1.Text = RadDatePicker1.SelectedDate.ToString ();
          }
     
          TextBox2.Text = RadDatePicker1.Enabled.ToString ();
       }
    }

    Thanks,

    Charles

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 05 Feb 2014 Link to this post

    Hello Charles,

    I will have to forward the first issue to our developers team, so they could further investigate it, but as for your second issue, disabling the RadDatePicker on client with set_enable(false) will not preserve on postback. You could create new item in our Ideas & Feedback Portal and suggest implementing such functionality in one of our future releases.

    Nevertheless, for the time being you could handle both of your requirements with the following approach:
    <script type="text/javascript">
        function pageLoad() {
            var datepicker = $find("<%= RadDatePicker1.ClientID %>");
        }
     
        function clearAndDisablePicker() {
            var picker = $find("<%= RadDatePicker1.ClientID %>");
            picker.clear();
            picker.set_enabled(false);
            var hiddenField = document.getElementById("HiddenField1");
            hiddenField.value = "Disabled";
        }
     
        function enablePicker() {
            var picker = $find("<%= RadDatePicker1.ClientID %>");
            picker.set_enabled(true);
            var hiddenField = document.getElementById("HiddenField1");
            hiddenField.value = "";
        }
    </script>
     
    <asp:HiddenField ID="HiddenField1" runat="server"/>
     
     
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     
    <telerik:RadButton ID="RadButton1" runat="server" Text="Enable picker" AutoPostBack="false" OnClientClicked="enablePicker"></telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Clear and disable picker" AutoPostBack="false" OnClientClicked="clearAndDisablePicker"></telerik:RadButton>
    And the code-behind:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RadDatePicker1.SelectedDate = DateTime.Now;
        }
     
        if (HiddenField1.Value == "Disabled")
        {
            RadDatePicker1.Enabled = false;
            RadDatePicker1.SelectedDate = null;
        }
        else
        {
            RadDatePicker1.Enabled = true;
        }
    }
     
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadDatePicker1.SelectedDate == null)
        {
            TextBox1.Text = "null";
        }
        else
        {
            TextBox1.Text = RadDatePicker1.SelectedDate.ToString();
        }
     
        TextBox2.Text = RadDatePicker1.Enabled.ToString();
    }

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top