asp.net同时调用JS和后台的无效的解决

如果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>");

  

 

原理就是先后台,再前台

posted @ 2014-10-21 16:24  奥巴马说你代码写的好  阅读(395)  评论(0编辑  收藏  举报