You need to set the Autopostback property to true for the TextBox to which you are adding the OnTextEvent.
This Way:
<form id="form1" runat="server">
<asp:ToolkitScriptManager runat="server">
</asp:ToolkitScriptManager>
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:TextBox ID="txtShippedDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtShippedDate">
</asp:CalendarExtender>
</td>
<td>
<asp:TextBox ID="txtReceivedDate" runat="server" OnTextChanged="txtReceivedDate_TextChanged"
AutoPostBack="true"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtReceiveddate">
</asp:CalendarExtender>
</td>
<td>
<asp:TextBox ID="txtQuantity" runat="server" OnTextChanged="txtReceivedDate_TextChanged"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
C#:
protected void txtReceivedDate_TextChanged(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM DateTable WHERE Id = 1 and ShippedDate <= @ShippedDate and ReceivedDate >= @ReceivedDate", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.Parameters.AddWithValue("@ShippedDate", this.txtShippedDate.Text);
cmd.Parameters.AddWithValue("@ReceivedDate", this.txtReceivedDate.Text);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
this.txtQuantity.Text = dt.Rows[0]["Quantity"].ToString();
}
}
}
}
}
Please dont use concatinated query in your code. Take the reference from my code.