You must Sign In to post a response.
  • Category: ASP.NET

    Called the click event

    Hello sir/Madam

    I have on click event (btn_Search_Click) and i taken a one input Text Box (html) in grid view.
    when I type on search Text Box and click on btn_Search_Click data will be displayed in grid view
    Now i want to use same functionality when user type in search Text Box and press "Enter" Can please suggest on this.

    In short i want to called the btn_Search_Click event when user enter from the Text Box
    Note : The input type has been taken under the Grid View

    Bhavik Shah
  • #765184

    What problem have you faced to implement the same?

    If you want to display the result based on your search criteria, then on click event of button bind the result to your gridview based on searching filter.


    Protected Void btnSearch_Click(Object sender, EventArgs e)
    Protected Void BindGrid()
    // call Stored procedure in application
    cmd = new SqlCommand("Get_Employees", con);
    cmd.CommandType = CommandType.StoredProcedure;

    // pass parameters to stored procedure
    cmd.Parameters.AddWithValue("@DeptNo", DeptNo);
    dt = new DataTable();

    // open connection

    da = new SqlDataAdapter(cmd);
    //fill datatable

    //bind datatable to gridview
    if (dt.Rows.Count > 0)
    GV.DataSource = dt;

    catch (Exception ex)
    throw ex;
    // Close the connection

    Refer above sample and implement as you want..

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765192
    Hello Sir

    I want to called the search_click event using "Enter key " when user type in search Box and press enter then i want to called this method

    Bhavik Shah

  • #765195
    Try this:
    .aspx page:
    <asp:GridView runat="server" ID="gvDemo" AutoGenerateColumns="true" PageIndex="2" AllowPaging="true" OnRowDataBound="gvDemo_RowDataBound">
    <asp:TextBox runat="server" ID="DemoTextBox" OnTextChanged="DemoTextBox_TextChanged" AutoPostBack="true" Text='<%# Eval("xyz") %>' />

    .cs page:
    protected void DemoTextBox_TextChanged(object sender, EventArgs e)
    TextBox t = (TextBox)sender;
    Response.Write("Text: " + t.Text +", ID: " + t.ClientID);

    Hope it helps.
    Shashikant Gurav

  • #765196
    Thanks Sir , Bu t i want to do this using onclik event (Key Press==32) "Enter Key" of textbox

  • #765198
    The code snippet I had given above will work as follows:
    When user input any text in textbox which belongs to gridview and fire enter, control will move to server side event DemoTextBox_TextChanged.
    Here you can do anything like call btn_Search_Click as follows:
    btn_Search_Click(sender, args);
    If you want to implement it using javascript, call a javascript function as follows:
    <asp:TextBox runat="server" ID="DemoTextBox" AutoPostBack="false" Text='<%# Eval("xyz") %>'
    onchange="javascript:return TestOnTextChange();" />

    function TestOnTextChange()
    __doPostBack("<%= btn_Search.UniqueID %>", "OnClick");
    document.getElementById('<%=btn_Search.ClientID %>').click();
    Shashikant Gurav

  • #765204
    do not do any code for it, Just set the 'UseSubmitBehavior' property of the button to 'true' and automatically your submit button gets clicked on enter press.
    This property Gets or sets a value indicating whether the Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism
    just set 'DefaultButton' property of the form to 'submit' button see below snippet
    this.Form.DefaultButton = "Button1";
    <asp:Panel ID="p" runat="server" DefaultButton="myButton">
    <%-- Text boxes here --%>
    <asp:Button ID="myButton" runat="server" />

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • Sign In to post your comments