I'm trying to format a date in a textbox using the OnTextChanged property of an asp:TextBox control. The date gets formatted properly, but it only works on actions that cause the page to refresh, like form buttons or drop-downs.
I need it to change when the textbox loses focus, and I thought that's what the OnTextChanged was supposed to do, but apparently not. Can anyone offer any help with this?
Here's the textbox and c# code:
<asp:TextBox ID="txtFromDate" Width="90px" runat="server" OnTextChanged="txtFromDate_dtFormat" />
protected void txtFromDate_dtFormat(object sender, EventArgs e)
{
txtFromDate.Text = Convert.ToDateTime(txtFromDate.Text).ToString("dd-MMM-yy");
}
I need it to change when the textbox loses focus, and I thought that's what the OnTextChanged was supposed to do, but apparently not. Can anyone offer any help with this?
Here's the textbox and c# code:
<asp:TextBox ID="txtFromDate" Width="90px" runat="server" OnTextChanged="txtFromDate_dtFormat" />
protected void txtFromDate_dtFormat(object sender, EventArgs e)
{
txtFromDate.Text = Convert.ToDateTime(txtFromDate.Text).ToString("dd-MMM-yy");
}