asp.net - Javascript event subscription after UpdatePanel async postback - Stack Overflow

I Have a problem with jquery event handler after async postback on asp page.I read this topic - it

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

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", { pleted: 
    function () {
    $('#btnCheckCustomerPhone').click();} 
  });

}
</script>

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!

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

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", { pleted: 
    function () {
    $('#btnCheckCustomerPhone').click();} 
  });

}
</script>

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!

Share Improve this question edited May 23, 2017 at 12:30 CommunityBot 11 silver badge asked May 31, 2011 at 13:08 MikkaMikka 672 silver badges8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The problem in your code is that the jQuery(document).ready is not run after the update panel, so you need to make your endRequest out of jQuery.

Try this way:

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

        function InitializeRequest(sender, args) {      
        }

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

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

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

        function InitPhonePattern(args) {
            $(args[0]).mask("+7 (999) 999-99-99", { pleted: 
            function () {
               $('#btnCheckCustomerPhone').click();} 
            });
        }
</script>

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;

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", { pleted:
            function () {
                $('#btnCheckCustomerPhone').click();
            }
         });
    }

</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745119524a4612330.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信