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
-
suggest any sample code is not a good way to ask here. Did you try anything so far?Soner Gönül– Soner Gönül2014-02-26 08:27:18 +00:00Commented 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>user1030181– user10301812014-02-26 08:28:36 +00:00Commented Feb 26, 2014 at 8:28
-
want to do it with asp controlsuser1030181– user10301812014-02-26 08:29:43 +00:00Commented Feb 26, 2014 at 8:29
-
This should work <form id="Form1"> defaultbutton="SubmitButton" defaultfocus="TextBox1" runat="server"></form>Learning– Learning2019-01-09 10:51:34 +00:00Commented Jan 9, 2019 at 10:51
Add a comment
|
3 Answers
Wrap that form in a panel, and make that button default button
<asp:Panel DefaultButton="button_id" runat="server">
your form here
</asp:Panel>
2 Comments
user1030181
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>
user1030181
Very Nice and Simple!
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
user1030181
Does not work with the above code