[CLOSED] Error creating custom control for date picker.

  1. #1

    [CLOSED] Error creating custom control for date picker.

    Hi,

    1) First of all create a new class project like Presentation and add a class Named "CustomDate.cs".

    using System;
    using System.Collections.Specialized;
    using System.Globalization;
    using Ext.Net;
    using System.Web;
    
    
    namespace Presentation
    {
        public class DIMDateField : DateField
        {
            public override string Format
            {
                get
                {
                    return "MM/dd/yyyy";
                }
    
    
                set
                {
                    base.Format = GetNativeDateFormat(false);
                }
            }
    
    
            public static string RegionalSettings
            {
                get
                {
                    string exception = string.Empty;
                    if (HttpContext.Current.Session["G_Regional_Setting"] == null)
                    {
                        try
                        {
                            CultureInfo cInfo = new CultureInfo(HttpContext.Current.Request.UserLanguages[0].ToString());
                            if (cInfo.IsNeutralCulture)
                            {
                                CultureInfo sInfo = CultureInfo.CreateSpecificCulture(cInfo.Name);
                                cInfo = sInfo;
                            }
    
    
                            HttpContext.Current.Session["G_Regional_Setting"] = cInfo.Name;
                        }
                        catch (Exception ex)
                        {
                            HttpContext.Current.Session["G_Regional_Setting"] = null;
                            exception = ex.Message;
                        }
                    }
                    if (HttpContext.Current.Session["G_Regional_Setting"] == null)
                    {
                        return string.Concat("Exp", exception);
                    }
                    else
                    {
                        return HttpContext.Current.Session["G_Regional_Setting"].ToString().Trim();
                    }
                }
            }
    
    
            public static string GetNativeDateFormat(bool canDisplayTime)
            {
                string format = string.Empty;
                try
                {
                    CultureInfo cInfo = new CultureInfo(RegionalSettings);
                    if (canDisplayTime)
                        format = cInfo.DateTimeFormat.ShortDatePattern + " " + cInfo.DateTimeFormat.LongTimePattern;
                    else
                        format = cInfo.DateTimeFormat.ShortDatePattern;
                }
                catch
                {
                    format = "dd.MM.yyyy";
                }
    
    
                return format;
            }
    
    
            protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
            {
                string val = postCollection[this.UniqueName];
                if (val != null)
                {
                    try
                    {
                        this.SelectedDate = DateTime.ParseExact(val, base.Format, System.Threading.Thread.CurrentThread.CurrentUICulture);
                    }
                    catch
                    {
                        try
                        {
                            this.SelectedDate = DateTime.ParseExact(val, base.Format, System.Threading.Thread.CurrentThread.CurrentCulture);
                        }
                        catch
                        {
                            this.SelectedDate = DateTime.MinValue;
                        }
                    }
                    finally
                    {
    
    
                    }
    
    
                    return true;
                }
    
    
                return false;
            }
        }
    }

    2) The main Web project contains the page "CustomDate.aspx"

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomDate.aspx.cs" Inherits="Samples_CustomDate" %>
    
    
    <%@ Register TagPrefix="DIM" Namespace="Presentation" Assembly="Presentation" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <div>
            <DIM:DIMDateField ID="dt_etd" Cls="edit-form-manitatory" runat="server" Vtype="daterange"
                Width="83" EnableKeyEvents="true">
                <CustomConfig>
                    <ext:ConfigItem Name="endDateField" Value="#{dt_eta}" Mode="Value" />
                </CustomConfig>
            </DIM:DIMDateField>
            <DIM:DIMDateField ID="dt_eta" runat="server" Vtype="daterange" Cls="edit-form-manitatory"
                Width="85" EnableKeyEvents="true">
                <CustomConfig>
                    <ext:ConfigItem Name="startDateField" Value="#{dt_etd}" Mode="Value" />
                </CustomConfig>
            </DIM:DIMDateField>
        </div>
        </form>
    </body>
    </html>

    When running this code, we are getting script issue like " Unable to get property 'setMinValue' of undefined or null reference".
    Guide us to resolve this issue.
    Last edited by Daniil; Nov 18, 2013 at 10:44 AM. Reason: [CLOSED]
  2. #2
    Hi @speedstepmem4,

    Please use:
    <ext:ConfigItem Name="endDateField" Value="#{dt_eta.ConfigID}" Mode="Raw" />
    and
    <ext:ConfigItem Name="startDateField" Value="#{dt_etd.ConfigID}" Mode="Raw" />
  3. #3

    Error creating custom control for date picker.

    Hi Daniil,

    Thanks for your suggestion. Now it's working fine..

Similar Threads

  1. [CLOSED] Creating Custom Control From Ext.Net.Label in MVC 4.0
    By randhir in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Dec 26, 2013, 2:04 PM
  2. [CLOSED] Setting filter date picker value throws an error
    By vadym.f in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 13, 2013, 2:42 AM
  3. Replies: 3
    Last Post: May 09, 2012, 4:28 PM
  4. [CLOSED] Creating custom control
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 29, 2010, 6:03 PM
  5. [CLOSED] Date Picker Control Design Issue
    By majestic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 01, 2010, 12:03 PM

Posting Permissions