shashi reddy

shashi reddy

  • NA
  • 186
  • 155.1k

textbox and button

Mar 29 2011 4:18 AM
hai 2 all

I have an option of search on my web page

<asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True"
ontextchanged="txtSearch_TextChanged"></asp:TextBox>

<asp:Button ID="btnSearch" runat="server" Text="Search" onclick="btnSearch_Click" />

---------------------------------------------------------------------
code
---------------------------------------------------------------------
protected void txtSearch_TextChanged(object sender, EventArgs e)
        {
           this.txtsearching();
       }

protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.txtsearching();
        }




private void txtsearching()
        {
            string strSQL = "";
            if (txtSearch.Text.Trim() == "")
            {
             strSQL = "select * from customers where flag=1 ORDER BY customer_code";
            }
            else
            {
                strSQL = "select  * from customers where flag=1 and (customer_code like '%" + txtSearch.Text.Trim() + "%' or customer_organization_name like '%" + txtSearch.Text.Trim() + "%')";

            }
            SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constring"].ToString());
            SqlDataAdapter sda = new SqlDataAdapter(strSQL, con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            gvKenyacustomers.DataSource = dt;
            gvKenyacustomers.DataBind();
            sda.Dispose();
            con.Dispose();
            dt.Dispose();
            txtSearch.Text = "";
          
        }
-------------------------------------------------------------------
1)my problem is when ever i am entering sme text in textbox txtSearch_TextChanged is fireing..twice
2) after entering the text in textbox and onclicking the search button btnSearch_Click is not fireing. txtSearch_TextChanged is fireing again

what is the solution for this...
when entering the text in textbox and hit the enter then txtSearch_TextChanged  has to fire only once
and when we enter the text in textbox and if hit the search button...
btnSearch_Click has to fire..


Answers (3)