I already made my code. But when user enter the
EnterKey, it is calling 2 button event on server side. I want to call only one event.
I have three Asp.net buttons,
<asp:Button ID="btnSearch" class="btn btn-info" runat="server" Text="SEARCH" Width="100" OnClick="btnSearch_Click" />
<asp:Button ID="btnSaveFile" runat="server" Text="SaveFile" OnClick="btnSaveFile_Click"/>
<asp:Button ID="btnLoadData" CssClass="btn btn-info" runat="server" Text="Ok" OnClick="btnLoadData_Click" />
Those 3 buttons will perform 3 different things. I have a textbox, once user enter the data and when they press the enter I want to call the
btnSaveFileclick event.
This is that text box
<asp:TextBox ID="txtFileName" CssClass="form-control" runat="server"></asp:TextBox>
Note
I already define the click function for btnSaveFile here is the code
$('#btnSaveFile').click(function () {
var fileNames = $('#txtFileName').val();
var flag = 'returnTrue';
$.ajax({
url: 'ReportTotalSalesPivot.aspx/getFileExistOrNot',
method: 'post',
async: false,
contentType: 'application/json',
data: '{fileName:"' + fileNames + '",reportName:"TotalSales"}',
dataType: 'json',
success: function (data) {
if (data.d === 'dataExist') {
flag = 'returnFalse';
$('#lblSaveErrorMsg').text('This filename already exist. Please change the name');
}
else {
//alert('else');
$(".FilterTable > tbody > tr").each(function () {
$("#hiddenTableRecord").val($("#hiddenTableRecord").val() + $(this).find(".FieldNameID").html() + "$$$" + $(this).find(".OperatorID").html() + "$$$");
});
$("#hiddenTableRecord").val('');
return true;
}
},
error: function (error) {
alert('Please Call Administrator');
}
});
//alert('faisal'+flag);
if (flag === 'returnFalse') {
return false;
}
});
The below code is for to call the above function.
$('#txtFileName').keydown(function (e) {
//enter key
var key = e.which;
if (key == 13) {
$('#btnSaveFile').click();
return false;
}
})
Problem
keydown function is working fine. But at the same time when I press the enter key it is calling
btnSearchserver side code also. It should not callbtnSearch. It should callbtnSaveFileon server side
Doubt
Totally I have 3 server side button, But it is calling only 2 why? (Just want to know the reason). Target: want to call only one button
Thanks
<asp:Button ID="button1" runat="server" UseSubmitBehavior="false" Text="just a button" />UseSubmitBehavior="false"?. So this button will not execute any more when user press the enter key?