Ragaei Mahmoud
Ragaei Mahmoud

Reputation: 457

textchanged event doesn't fire

I have CalendarExtender and bound it to a textbox but when i write code in textchanged event found that it doesn't fire;here my code snippet:

<asp:TextBox ID="txtFromDate" MaxLength="10" Width="150" CssClass="textbox" 
    runat="server" />

code behind :

protected void txtFromDate_TextChanged(object sender, EventArgs e)
{
    if (Convert.ToDateTime(txtFromDate.Text) < DateTime.Today)
    {
        _lblErroFromDate.Visible = true;
        _lblErroFromDate.Text = "Please enter valid date !";
    }
    else
        _lblErroFromDate.Visible = false;
}

Upvotes: 1

Views: 4250

Answers (3)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

You forgot to set AutoPostBack="true".

Upvotes: 5

Akram Shahda
Akram Shahda

Reputation: 14781

The TextChanged event wont be fired until the page posts back to the server.

TextBox controls don't post back the page to the server by default when their events occure. You can change this behavior by setting the AutoPostBack property value to true.

Upvotes: 4

Shekhar
Shekhar

Reputation: 11788

I think setting AutoPostBack property to true will solve the problem.

Upvotes: 2

Related Questions