How to call postback from TextBox on TextChange event without focus being changed?
The sitiation: I need to databind the gridview inside the Ajax UpdatePanel each time user types letter inside my TextBox control. How to override the TextChange event to force it do postback for me? Thanks!
<script type="text/javascript">
function ace1_itemSelected(sender, e) {
var hdCustID = $get('<%= hdCustID.ClientID %>');
hdCustID.value = e.get_value();
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblCustName" Text="Cust Name:" AssociatedControlID="txtCustName" runat="server" />
<asp:TextBox ID="txtCustName" AutoPostBack="false" AutoComplete="Off" runat="server" OnTextChanged="txtCustName_TextChanged" />
<ajaxToolkit:AutoCompleteExtender id="ace1" targetcontrolid="txtCustName" ServicePath="~/WebServices/FoodItemSuggestionService.asmx" servicemethod="FindTitles"
minimumprefixlength="1" OnClientItemSelected="ace1_itemSelected" firstrowselected="false" runat="server" />
<asp:HiddenField ID="hdCustID" runat="server" />
<br />
<br />
<br />
<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="4" BorderStyle="Groove">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<asp:BoundField DataField="Title" HeaderText="Название" SortExpression="Title" />
<asp:BoundField DataField="CategoryTitle" HeaderText="Категория" SortExpression="CategoryTitle" />
</Col开发者_运维技巧umns>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
protected void txtCustName_TextChanged(object sender, EventArgs e)
{
try
{
gvCustomer.DataSource = FoodItemBO.FindFoodItems(hdCustID.Value);
gvCustomer.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
Try this one:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
JQUERY:
$("#txtName").keydown(function(){
$("#form1").submit();
});
精彩评论