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!

textbox ontextchanged event doesn't fire with specific dates

Status
Not open for further replies.

jimktrains

IS-IT--Management
Jan 19, 2007
50
US
I have a textbox that is for a date field. There are two DropDownLists that get loaded after the date is entered because what is available in them depends on the date entered. There is a OnTextChanged event attached to the textbox. When the user enters a date, the DropDownLists are always loaded. When the user is loading the record to edit, meaning they are not entering the date, is it loaded from code behind, the DropDownLists get loaded, except when the month and date are two digit numbers. If the date were 09/10/2013, it works, if the date is 10/09/2013 it works, but if the date is 10/10/2013, the DropDownLists are not loaded. The method to build the DropDownLists is not called but it is for the other dates (09/09/2013 and 10/09/2013). I have devised a work around to set a flag when it is called and call it after the record is loaded only if the flag isn't set.

Here's the code for the texbox.
<asp:TextBox ID="txt_date" runat="server" Width="80px" MaxLength="10" AutoPostBack="true" OnTextChanged="set_fac" />

I can live with this solution, but wondering why it doesn't work in the first place bothers me. Any ideas?
Jim
 
Not exactly understanding the problem you are having.
The textbox's OnTextChanged event does not fire when the textbox is changed(typing into it) or when you tab off. It is only fired if the value has changed AND postback occurs:

This is from this article:

The TextChanged event is raised when the content of the text box changes between posts to the server. The event is only raised if the text is changed by the user; the event is not raised if the text is changed programmatically.
 
I may not have explained well enough.
The user selects a record from a grid on another page. This passes the selected data from that page to the next one (via querystring parameters). The next page retrieves the record based on the data passed from the previous page. It then populates the fields on this page from the record retrieved.

If the month or date is only a single digit (9/25/2013), the two drop down lists get populated. But if the date has a 2 digit month and 2 digit day (10/25/2013) the drop down lists are not populated. The method to populate them is not even called.

The autopostback='true' should cause the method to populate the drop down lists to be called, and it does when the date is a single digit month or day. I know autopostback='true' would cause a postback when the field looses focus. Although the field is being populated from code behind, it works on the single digit dates so that part does work.
 
You will need to post some code so I can see how your page is working and what you expect. Without seeing your code I really can't help that much.
Please show the aspx markup and also the code behind for the second page with the drop down lists.
 
I was trying to create a small program to duplicate this. I couldn't get it to reproduce the problem until I added the Ajax Calendar Extender. Even if you load the field in Code Behind, it takes it and redisplays it, eliminating leading zeros from the month and day, thus changing the field causing the ontextchange event to fire. When the month and day were two digits, it remained the same so the ontextchanged event didn't fire. So now I know what caused this.

Thanks jbenson001 for attempting to help.
 
Ahh you didn't mention that you were using the Ajax controls That would have been helpful to know.

Glad you found the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top