<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DateBox1.ascx.cs" Inherits="UserControl_DateBox1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox runat="server" ID="txtBox" CausesValidation="false" AutoPostBack="false"
<asp:MaskedEditExtender ClearTextOnInvalid="true" ID="meedate" runat="server" AutoComplete="false"
Enabled="false" TargetControlID="txtBox" Mask="99/99/9999 99:99" MaskType="DateTime"
<asp:ImageButton ID="calButton" Width="15px" Height="15px" runat="server" ImageUrl="~/Images/calendar_blue.png"
<%--<asp:TextBox ID="hdnDate" runat="server" Visible="false" CssClass="cssText"></asp:TextBox>--%>
<asp:TextBoxWatermarkExtender runat="server" TargetControlID="txtBox" WatermarkText="dd/MM/yyyy"
<%--<asp:RequiredFieldValidator runat="server" ControlToValidate="txtBox" ErrorMessage="error" />--%>
<%-- <asp:CustomValidator runat="server" ErrorMessage="*" ControlToValidate="txtBox"
<asp:RequiredFieldValidator ID="rfvTxtBox" runat="server" ControlToValidate="txtBox"
ErrorMessage="*" Style="color: Red; font-size: larger; font-weight: bold;"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ControlToValidate="txtBox" runat="server" ErrorMessage="*"
ID="revDDMMYYYY" ForeColor="Red" ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"
Style="color: Red; font-size: smaller; font-weight: bold;" Visible="false" />
<asp:RegularExpressionValidator ControlToValidate="txtBox" runat="server" ErrorMessage="*"
ID="revDDMMYYYYHHMMSS" ForeColor="Red" ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))\s+(?:2[0-3]|[01][0-9]):[0-5][0-9]\b$"
Style="color: Red; font-size: smaller; font-weight: bold;" Visible="false" />
<%-- <asp:RegularExpressionValidator ControlToValidate="txtBox" runat="server" ErrorMessage="error" ID="rev" ValidationExpression="(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$" />
<asp:CalendarExtender ID="cal" runat="server" TargetControlID="txtBox" PopupButtonID="calButton" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControl_DateBox1 : System.Web.UI.UserControl
{
// private DateTime v_Values;
private String v_Format = "dd/MM/yyyy";
// private String v_Text = "";
private Boolean v_ShowDate = false;
// private String validationExp;
private Boolean v_AutoPostBack = false;
private String v_CssClass = "";
private Boolean v_Validate_Yn = false;
private short v_TabIndex;
public Boolean v_ReadOnly = false;
public Boolean v_MonthYear = false;
public Boolean v_Masked = false;
protected void Page_Load(object sender, EventArgs e)
{
if (v_ShowDate == true)
{
revDDMMYYYY.Enabled = false;
revDDMMYYYYHHMMSS.Enabled = true;
revDDMMYYYY.Visible = false;
revDDMMYYYYHHMMSS.Visible = true;
revDDMMYYYYHHMMSS.ControlToValidate = "txtBox";
}
else
{
revDDMMYYYY.Enabled = true;
revDDMMYYYYHHMMSS.Enabled = false;
revDDMMYYYY.Visible = true;
revDDMMYYYYHHMMSS.Visible = false;
revDDMMYYYY.ControlToValidate = "txtBox";
}
}
public Boolean MaskedEditor
{
get
{
meedate.Enabled = v_Masked;
return v_Masked;
}
set
{
v_Masked = value;
meedate.Enabled = v_Masked;
}
}
public Boolean RequiredValidator
{
get
{
rfvTxtBox.Enabled = v_Validate_Yn;
return v_Validate_Yn;
}
set
{
rfvTxtBox.Enabled = value;
//txtBox.AutoPostBack = value;
v_Validate_Yn = value;
}
}
public String CssClass
{
get
{
v_CssClass = txtBox.CssClass;
return v_CssClass;
}
set
{
v_CssClass = value;
txtBox.CssClass = v_CssClass;
}
}
public String Values
{
get
{
//return String.Format("{0:dd/mm/yyyy HH:mm:ss}",txtBox.Text);
if (v_ShowDate == true)
{
return String.Format("{0:dd/MM/yyyy HH:mm}", txtBox.Text);
}
else
{
return String.Format("{0:dd/MM/yyyy}", txtBox.Text);
}
//return DateTime.ParseExact(txtBox.Text, v_Format, System.Globalization.CultureInfo.InvariantCulture);
}
//set
//{
// // v_Values = String.Format("{0:dd/MM/yyyy HH:mm:ss}", value);
// // txtBox.Text =(DateTime.ParseExact(value, v_Format, System.Globalization.CultureInfo.InvariantCulture)).ToString();
// //txtBox.Text = String.Format(v_Format,value);
//}
}
public DateTime displayText
{
set
{
txtBox.Text = value.ToString(v_Format);
}
}
public Boolean ShowTime
{
get
{
if (v_ShowDate == true)
{
v_Format = v_Format + " HH:mm";
revDDMMYYYY.Enabled = false;
revDDMMYYYYHHMMSS.Enabled = true;
revDDMMYYYY.Visible = false;
revDDMMYYYYHHMMSS.Visible = true;
// revDDMMYYYY.ControlToValidate = "hdnDate";
revDDMMYYYYHHMMSS.ControlToValidate = "txtBox";
}
else
{
v_Format = v_Format + "";
revDDMMYYYY.Enabled = true;
revDDMMYYYYHHMMSS.Enabled = false;
revDDMMYYYY.Visible = true;
revDDMMYYYYHHMMSS.Visible = false;
//revDDMMYYYYHHMMSS.ControlToValidate = "hdnDate";
revDDMMYYYY.ControlToValidate = "txtBox";
}
return v_ShowDate;
}
set
{
v_ShowDate = value;
if (v_ShowDate == true)
{
v_Format = v_Format + " HH:mm";
revDDMMYYYY.Enabled = false;
revDDMMYYYYHHMMSS.Enabled = true;
revDDMMYYYY.Visible = false;
revDDMMYYYYHHMMSS.Visible = true;
revDDMMYYYY.ControlToValidate = "hdnDate";
revDDMMYYYYHHMMSS.ControlToValidate = "txtBox";
}
else
{
v_Format = v_Format + "";
revDDMMYYYY.Enabled = true;
revDDMMYYYYHHMMSS.Enabled = false;
revDDMMYYYY.Visible = true;
revDDMMYYYYHHMMSS.Visible = false;
revDDMMYYYYHHMMSS.ControlToValidate = "hdnDate";
revDDMMYYYY.ControlToValidate = "txtBox";
}
tbwe.WatermarkText = v_Format;
cal.Format = v_Format;
//validationExp = v_Format.Replace("dd/", HMISWEB.DateValidation.dd);
//validationExp = validationExp.Replace("MM/", HMISWEB.DateValidation.MM);
//validationExp = validationExp.Replace("yyyy", HMISWEB.DateValidation.yyyy);
//validationExp = validationExp.Replace("HH", HMISWEB.DateValidation.hh24);
//validationExp = validationExp.Replace("mm", HMISWEB.DateValidation.mm);
//validationExp = validationExp.Replace("tt", HMISWEB.DateValidation.ss);
//validationExp = "((" + validationExp + "))";
//rev.ValidationExpression = validationExp;
}
}
public String Format
{
get
{
return v_Format;
}
set
{
if (v_ShowDate == true)
{
v_Format = value + " HH:mm";
}
else if (v_ShowDate == false)
{
v_Format = value;
}
tbwe.WatermarkText = v_Format;
cal.Format = v_Format;
// validationExp = v_Format.Replace("dd/",HMISWEB.DateValidation.dd);
// validationExp = validationExp.Replace("MM/", HMISWEB.DateValidation.MM);
// validationExp = validationExp.Replace("yyyy", HMISWEB.DateValidation.yyyy);
// validationExp = validationExp.Replace("HH", HMISWEB.DateValidation.hh24);
// validationExp = validationExp.Replace("mm", HMISWEB.DateValidation.mm);
// validationExp = validationExp.Replace("ss", HMISWEB.DateValidation.ss);
// validationExp = "((" + validationExp + "))";
//rev.ValidationExpression = validationExp;
}
}
public Boolean ValidateDate()
{
String localDateValue;
System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
DateTime localDateTime;
localDateValue = txtBox.Text;
try
{
localDateTime = DateTime.ParseExact(localDateValue, v_Format, provider);
return true;
}
catch
{
return false;
}
}
public Boolean AutoPostBack
{
get
{
txtBox.AutoPostBack = v_AutoPostBack;
return v_AutoPostBack;
}
set
{
txtBox.AutoPostBack = value;
v_AutoPostBack = value;
}
}
public short TabIndex
{
get
{
return v_TabIndex;
}
set
{
v_TabIndex = value;
txtBox.TabIndex = value;
}
}
protected override void OnInit(EventArgs e)
{
this.txtBox.TextChanged += new EventHandler(txtBox_TextChanged);
base.OnInit(e);
}
void txtBox_TextChanged(object sender, EventArgs e)
{
OnBubbleTextChanged(e);
}
public event EventHandler BubbleTextChanged;
protected void OnBubbleTextChanged(EventArgs e)
{
rfvTxtBox.Validate();
if (revDDMMYYYY.Enabled)
{
revDDMMYYYY.Validate();
if (BubbleTextChanged != null && rfvTxtBox.IsValid && revDDMMYYYY.IsValid)
{
BubbleTextChanged(this, e);
}
else
{
txtBox.Focus();
}
}
else if (revDDMMYYYYHHMMSS.Enabled)
{
revDDMMYYYYHHMMSS.Validate();
if (BubbleTextChanged != null && rfvTxtBox.IsValid && revDDMMYYYYHHMMSS.IsValid)
{
BubbleTextChanged(this, e);
}
else
{
txtBox.Focus();
}
}
}
public String VaidationGroup
{
get
{
//if (rfvTxtBox.Enabled)
//{
return rfvTxtBox.ValidationGroup;
//}
}
set
{
if (rfvTxtBox.Enabled)
{
rfvTxtBox.ValidationGroup = value;
}
}
}
public Boolean ReadOnly
{
get
{
return txtBox.ReadOnly;
}
set
{
txtBox.ReadOnly = value;
if (value)
{
calButton.Visible = false;
cal.Enabled = false;
}
else
{
calButton.Visible = true;
cal.Enabled = true;
}
}
}
}