如果js是个定时器,那么就不走后台
<asp:Button runat="server" type="button" Text="重新发送邮件" ID="btnReRendEmail" class="btn-defaut02" OnClick="btnReRendEmail_Click" />
//重新发送邮箱事件
var waitTime = 50;
function reRendEmail() {
var btnRe = document.getElementById("btnReRendEmail");
if (waitTime == 0) {
btnRe.removeAttribute("disabled");
btnRe.value = "重新发送邮件";
waitTime = 50;
} else {
btnRe.setAttribute("disabled", true);
btnRe.setAttribute('value',waitTime + "秒后可以重新发送");
waitTime--;
setTimeout(function() {
reRendEmail();
},
1000)
}
}
解决方法是,先走后台,然后在后台执行完最后一个方法的时候调用前台的JS
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>reRendEmail();</script>");
原理就是先后台,再前台