UpdatePanel ASP.NET TextBox(与Google搜索框一样)

时间:2013-11-20 11:24:18

标签: c# asp.net textbox updatepanel

首先我想指出我已经使用Javascript和ASP.Net来解决。但是,我听说UpdatePanel和TextBox(char by char过滤器)。我更快地相信这一点,因为我可以节省很多时间进行渲染。

我试着跟着 How to trigger an UpdatePanel by a TextBox control?

但它不会起作用。这是示例

 protected void Page_Load(object sender, EventArgs e)
    {
        string query = cmd;
        JB.CommandResponse response = JB.Master.DataBase.ExecuteQuery(query); //database
        if (!Page.IsPostBack)
        {
            GridView_product.DataSource = response.Get_DataRecords();
            GridView_product.DataBind();
            TextBox_search.Attributes.Add("onkeyup", "refresh()");
            return; 
        }

        response = JB.Master.DataBase.ExecuteQuery(query); //database
        query += " and code_p like '%" + TextBox_search.Text + "%' or " +
        "name_p like '%" + TextBox_search.Text + "%'";

        GridView_product.DataSource = response.Get_DataRecords();
        GridView_product.DataBind();          
    }

// .aspx的

<script>
var refresh = function () {
  __doPostBack('<%= myUpdatePanel.ClientID %>', '');
};
</script>

<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<asp:TextBox ID="TextBox_search" runat="server" CssClass="textbox left"></asp:TextBox>


<asp:UpdatePanel runat="server" ID="myUpdatePanel" UpdateMode="Always">
  <ContentTemplate>
    <asp:GridView ID="GridView_product" runat="server" CssClass="gridview"   ShowHeaderWhenEmpty="true"></asp:GridView>

  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="TextBox_search" />
  </Triggers>
</asp:UpdatePanel>

0 个答案:

没有答案