UpdatePanel的异步回发后的Javascript事件订阅 [英] Javascript event subscription after UpdatePanel async postback

查看:80
本文介绍了UpdatePanel的异步回发后的Javascript事件订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp.net页面异步回发后用jQuery事件处理的一个问题。
我读这个话题 - 这是一个很好的解决方案,但我需要一个单独的函数。
所以我使用的jQuery插件蒙面

I Have a problem with jquery event handler after async postback on asp.net page. I read this topic - it's a good solution, but I need a separate function. So I'm using jquery masked plugin.

我的js code现在是:
    

My js code now is:

<script type="text/javascript">

jQuery(document).ready(function () {
  var control = $("#txtCustomerPhone");

  InitPhonePattern(this, control);

  var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_endRequest(InitPhonePattern(this, control));
 });

 function InitPhonePattern(sender, args) {
  $(args[0]).mask("+7 (999) 999-99-99", { completed: 
    function () {
    $('#btnCheckCustomerPhone').click();} 
  });

}
</script>

正如你看到面罩被初始化2次:在文档就绪()和异步回发后(上endRequest())。但是面膜插件没有异步回发后映射。

As you see mask was initialized 2 times: on document Ready() and after async postback (on endRequest()). But mask plugin is not mapped after async postback.

有人了解的问题吗?我会帮忙不胜感激!

Someone understands problem? I would be grateful for help!

推荐答案

我要这么说感谢 Aristos的求助和正确的方向!
在您的code我只固定字符串:

I want so say thanks to Aristos for help and right direction! In your code I fixed only this string:

jQuery(document).ready(Init);//direct transfer function not work;

所以最终code是这样的:

So final code looks like this:

<script type="text/javascript">
     var prm = Sys.WebForms.PageRequestManager.getInstance();
     prm.add_endRequest(EndRequest);

     function EndRequest(sender, args) {
         Init();
     }

     $(document).ready(function () {
         Init();
     });

     function Init() {
         var control = $('#txtCustomerPhone');
         InitPhonePattern(control);
     }

     function InitPhonePattern(args) {
         $(args).mask("+7 (999) 999-99-99", { completed:
            function () {
                $('#btnCheckCustomerPhone').click();
            }
         });
    }

</script>

这篇关于UpdatePanel的异步回发后的Javascript事件订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆