This is my HTML code :
@using (Html.BeginForm("Index", "EmployeeList", FormMethod.Post, new {defaultbutton = "searchBtn" }))
{
@Html.TextBox("SearchString", ViewBag.SearchString as string, new { @id = "SearchString", @class = "form-control", placeholder = "Search Name" })
<button type="submit" name="MyButton" value="Export" class="btn btn-sm btn-danger">
<button type="submit" name="MyButton" value="Search" id="searchBtn" class="btn btn-sm btn-warning">
}
According to my page design I have to write "Export" button's html code before "Search" button.
While I press enter after filling search text 'export' button gets clicked, instead of that I need 'Search' button clicked.
One can set the default button at the form level meaning of all the buttons in the form the one that is set as default will be triggered whenever user presses Enter key. You just need to provide the ID of the Button to the defaultbutton property and it is set as default.
method property represents the HTTP method used to submit the <form> . Unless explicitly specified, the default method is 'get'.
You can handle kewdown event :
<script type="text/javascript">
$(document).bind('keydown', function (e) {
if (e.which === 13) { // return
$('#searchBtn').trigger('click');
}
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With