Monday, November 02, 2009

Problem to display date in the MaskedTextBoxControl in dotnet


When you try to display date value to MaskedTextBox then it show different date in the field especially when you have single digit on the date. Even though MaskedTextBox control "Mask" property set it to "00/00/0000".


When you try to assign the date into this field like:




MaskTextBox.Text = "1/12/2009", it will display in the field like "11/22/009_"




To overcome this issue you have to send your date with proper format like below


MaskedTextBox.Text = Format(Convert.ToDateTime("1/12/2009 5:58:00 PM"), "MM/dd/yyyy")


MaskedTextBox.Text = Format(Convert.ToDateTime(Date.Now), "MM/dd/yyyy")


Now it will display in the field as a correct date format "1/12/2009".


No comments: