[英]Server Click event is not firing after client click event return true in asp.net
I am creating a website and use a popup for exporting grid data to excel sheet but I have trouble I have created a javascript method and call it on client click of asp.net here is my function 我正在创建一个网站,并使用弹出窗口将网格数据导出到Excel工作表,但是我遇到了麻烦,我创建了一个javascript方法,并在客户端单击asp.net时调用它,这是我的功能
<script>
function change() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Store/ViewStock.aspx/CountStock",
data: "{'fromDate':'" + $('#<%= txtFromDate.ClientID%>').val() + "', 'ToDate':'" + $('#<%= txtToDate.ClientID%>').val() + "'}",
dataType: "json",
success: function (data) {
if (data.d != null)
var count = data.d[0].Count;
if (count > 0) {
$('#emptyDataRow').hide();
return true;
}
else {
$('#emptyDataRow').show();
return false;
}
},
});
}
</script>
And 和
Here is my button 这是我的按钮
Close 关
I have used OnClientClick="return (!change()){ return false;}"
but its server click not working when its true Help me how to tackle this issue?? 我已经使用过
OnClientClick="return (!change()){ return false;}"
但服务器服务器单击为true时不起作用。帮助我如何解决此问题? Thanks 谢谢
$.ajax is an asynchronous function. $ .ajax是一个异步函数。 So those return calls wont work.
因此,这些回电将无法进行。
Why are you concerned with the return of the change
function? 您为什么要关注
change
功能的返回? You can just do: 您可以这样做:
onclientclick="change()"
Also as a side note, I think it's better to define your variables outside of an if statement, so they are not undefined downstream: 另外请注意,我认为最好在if语句之外定义变量,因此在下游也不是未定义变量:
var count = 0;
if (data.d != null)
count = data.d[0].Count;
if (count > 0) {
$('#emptyDataRow').hide();
}
else {
$('#emptyDataRow').show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.