Nov 18, 2013, 5:17 AM
[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".
2) The main Web project contains the page "CustomDate.aspx"
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.
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]