Quantcast
Channel: AjaxControlToolkit Work Item Rss Feed
Viewing all articles
Browse latest Browse all 4356

Closed Issue: MaskedEditExtender does not handle century properly in a date mask [16186]

$
0
0
When using a MaskedEditExtender with the mask attribute set to "99/99/9999" and the MaskType attribute set to "Date", the extender does not handle the century properly. No matter what the AutoComplete attribute is set to, if a user enters a two digit year (for example: "08") the masked edit will complete the year as 1908. It should at least use the current century, which can be accomplished like so:
var right_now=new Date();
[some variable] = right_now.getYear();

In my pages, I have used a hack - it works, but it's stupid to have to do this, and it causes a post back, which makes the page lose focus (which can be annoying when you're trying to tab through the controls on the list, and it goes to the default button after you go through a date text box). The following is a method I attach to the "OnTextChanged" attribute of a textbox:
protected void DateBox_TextChanged(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)sender;
Boolean blnReturnDate = false;
string strDateText = tb.Text;
char[] splitter = {'/'};
string[] strArrDate = new string[3];
string strYear = "";

try
{
strArrDate = strDateText.Split(splitter);
}
catch
{
//do nothing
}

if (strArrDate.Length < 3)
{
strArrDate = new string[3];
strArrDate[2] = "";
}

string strLastCentury;
string strCurrCentury;

strCurrCentury = Convert.ToString(System.DateTime.Now.Year).Substring(0, 2) + "00";
strLastCentury = Convert.ToString(Convert.ToInt32(strCurrCentury) - 100);

// Check the length of the year, if 2 then re-calculate
if (strArrDate[2].Replace("_", "").Length == 2)
{
blnReturnDate = true;
strYear = strArrDate[2].Replace("_", "");

if (Convert.ToInt32(strYear) >= 49)
{
strYear = strLastCentury.Substring(0, 2) + strYear;
}
else
{
strYear = strCurrCentury.Substring(0, 2) + strYear;
}
}
else if (strArrDate[2].Replace("_", "").Length < 2)
{
strYear = Convert.ToString(System.DateTime.Now.Year);
}

if (blnReturnDate)
{
tb.Text = strArrDate[0] + "/" + strArrDate[1] + "/" + strYear;
}
}
Comments: Issues is closed as it is fixed with April 2013 release.

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>