Text box TextChangedEvent not firing

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

I have a textbox box and a date picker.When i select a date through
the date picker, it fills the textbox with the selected date.Now, i
have a text changed event for the textbox. This event fires only if i
key in a date manually and not if i use the date picker.

How can i make the textchanged event to fire when i use the date
picker?
 
When a date is selected using the date picker and it fills the TextBox, is
this done using a postback or using JavaScript? If it is done using a
postback, the TextChanged event will not be triggered because the text
didn't change since the last postback. If this is the case, here are several
options:

Option #1: Get the date from the datepicker, this way you can get it as a
Date rather than need to worry about converting a String into a Date. If you
want to allow the user to enter the date manually instead, try following
this process (you may need to add a little validation to make sure you do
not get an error converting from String to Date):

1. Get the date from the date picker
2. In the TextChanged event, use the date from the TextBox

Option #2: You can also try using AJAX, which would be my choice.

Option #3: Write your own control.

Good Luck!
 
 I have a textbox box and a date picker.When i select a date through
the date picker, it fills the textbox with the selected date.Now, i
have a text changed event for the textbox. This event fires only if i
key in a date manually and not if i use the date picker.

How can i make the textchanged event to fire when i use the date
picker?

Hi

Only one control can trigger a PostBack at any one time and hence
"fire" it's event handler.

No problem!

If you want a piece of code to be executed on the server in response
to more than one control then write a separate routine to handle it
and then put a statement to call the routine in the event handlers of
each control.

For example:

private void SaveDate(DateTime ADate)
{
//code to save date to datasource or whatever
}

protected TextBox1_TextChanged(object sender, EventArgs e)
{
DateTime inputDate = DateTime.Parse(TextBox1.Text);
SaveDate(inputDate);
Calendar1.SelectedDate = inputDate;
Calendar1.VisibleDate = inputDate;
}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
SaveDate(Calendar1.SelectedDate);
TextBox1.Text = Calendar1.Date.ToShortDateString();
}

HTH
 
Back
Top