3

I have a asp.net Textbox & Button in WebForm Page. When the enter key is pressed in textbox the button click should happen to load data to gridview on the page. Please suggest any sample code

4
  • suggest any sample code is not a good way to ask here. Did you try anything so far? Commented Feb 26, 2014 at 8:27
  • <input type="text" id="txtSearch" onkeydown="if (event.keyCode == 13) document.getElementById('Button1').click()"/> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" ></asp:Label> Commented Feb 26, 2014 at 8:28
  • want to do it with asp controls Commented Feb 26, 2014 at 8:29
  • This should work <form id="Form1"> defaultbutton="SubmitButton" defaultfocus="TextBox1" runat="server"></form> Commented Jan 9, 2019 at 10:51

3 Answers 3

8

Wrap that form in a panel, and make that button default button

<asp:Panel DefaultButton="button_id" runat="server">
your form here
</asp:Panel> 
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent One <asp:Panel ID="Panel1" runat="server" DefaultButton="Button1"> Name:<asp:TextBox ID="txtName" runat="server" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="display: none" /> </asp:Panel> <asp:Label ID="Label1" runat="server"></asp:Label>
Very Nice and Simple!
0

You can refer the same kinda question asked in the forum already....check here

Comments

0

You can try:

In HTML:

    <asp:TextBox ID="TextBox1" runat="server" onKeyDown="submitButton(event)"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

And javascript:

function submitButton(event) {
        if (event.which == 13) {
            $('#Button1').trigger('click');
        }
    }

Code bihide:

protected void Button1_Click(object sender, EventArgs e)
{
    //load data and fill to gridview
}

Hope this help

1 Comment

Does not work with the above code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.