Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting date in textbox without page refresh

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
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");
}
 
The OnTextChanged event is a server side event, meaning, a postback needs to occur inorder for that event to fire. To do what you want, you need to use javascript's onblur() event.
 
Thanks! Went the javascript route instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top