locked
how to add Sys.WebForms.PageRequestManager.getInstance to my script RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my javascript it run fine if i dont use updatepanel

    <script>
            $(function () {
    
                $("#ctl00_ContentPlaceHolder1_TxtRate,#ctl00_ContentPlaceHolder1_TxtSale_Qty").blur(function () {
                    var rate = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRate").val());
                    var qty = parseFloat($("#ctl00_ContentPlaceHolder1_TxtSale_Qty").val());
                    if (!isNaN(rate * qty)) {      
                        $("#ctl00_ContentPlaceHolder1_TxtAmount").text(rate * qty);
                    }
                   
                })
                $("#ctl00_ContentPlaceHolder1_TxtDiscount").blur(function () {
    
                    $("#ctl00_ContentPlaceHolder1_Label15").text(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) * parseFloat($("#ctl00_ContentPlaceHolder1_TxtDiscount").val()) / 100);
                        
                        $("#ctl00_ContentPlaceHolder1_TextBox2").val(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) - parseFloat($("#ctl00_ContentPlaceHolder1_Label15").text()));
                        
                        var Tax = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val())
                         if (Tax < 1000) {
                        $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 5 / 100);           
                        }
                        else if (Tax > 1000) {
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);           
                        }
                        else{
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);        
                        }
                        
                        
                        var a1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox5").val());
                        var b1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
                        var c1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
     
                       $("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text(a1 + b1);
                       
    //                   if (c1 < 0) {
    //                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
    //                   }
                       
                   $("#ctl00_ContentPlaceHolder1_TxtRO").blur(function () {
                        var k1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text());
                        var k2 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
                   
                   
                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(k1 - k2);
    
    })
    
                })
                
                
    
    
            })
    
        </script>

    How to add this code in my script

      $(document).ready(function () {
                bindKeyUp();
                var prm = Sys.WebForms.PageRequestManager.getInstance();
    
                prm.add_endRequest(function (e) {
                  bindKeyUp();
                });
            });

    Thank You

    Thursday, November 22, 2018 8:40 AM

Answers

  • User-893317190 posted

    Hi Gopi.MCA,

    You could define a function at first , and call your function in $(function(){})  and  prm.add_endRequest(function (e) {});

    Below is my code.

     <script>
    //define a function to call
            function myFunction() {
    
                 $("#ctl00_ContentPlaceHolder1_TxtRate,#ctl00_ContentPlaceHolder1_TxtSale_Qty").blur(function () {
                    var rate = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRate").val());
                    var qty = parseFloat($("#ctl00_ContentPlaceHolder1_TxtSale_Qty").val());
                    if (!isNaN(rate * qty)) {      
                        $("#ctl00_ContentPlaceHolder1_TxtAmount").text(rate * qty);
                    }
                   
                })
                $("#ctl00_ContentPlaceHolder1_TxtDiscount").blur(function () {
    
                    $("#ctl00_ContentPlaceHolder1_Label15").text(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) * parseFloat($("#ctl00_ContentPlaceHolder1_TxtDiscount").val()) / 100);
                        
                        $("#ctl00_ContentPlaceHolder1_TextBox2").val(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) - parseFloat($("#ctl00_ContentPlaceHolder1_Label15").text()));
                        
                        var Tax = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val())
                         if (Tax < 1000) {
                        $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 5 / 100);           
                        }
                        else if (Tax > 1000) {
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);           
                        }
                        else{
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);        
                        }
                        
                        
                        var a1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox5").val());
                        var b1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
                        var c1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
     
                       $("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text(a1 + b1);
                       
    //                   if (c1 < 0) {
    //                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
    //                   }
                       
                   $("#ctl00_ContentPlaceHolder1_TxtRO").blur(function () {
                        var k1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text());
                        var k2 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
                   
                   
                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(k1 - k2);
    
    })
    
                })
    
            }
    
    
    $( function () { //call the function after the page is loaded to bind event myFunction(); var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function (e) { // call the function here to rebind the event after updatepanel returns myFunction(); }); } ) </script>

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 23, 2018 3:29 AM

All replies

  • User-893317190 posted

    Hi Gopi.MCA,

    You could define a function at first , and call your function in $(function(){})  and  prm.add_endRequest(function (e) {});

    Below is my code.

     <script>
    //define a function to call
            function myFunction() {
    
                 $("#ctl00_ContentPlaceHolder1_TxtRate,#ctl00_ContentPlaceHolder1_TxtSale_Qty").blur(function () {
                    var rate = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRate").val());
                    var qty = parseFloat($("#ctl00_ContentPlaceHolder1_TxtSale_Qty").val());
                    if (!isNaN(rate * qty)) {      
                        $("#ctl00_ContentPlaceHolder1_TxtAmount").text(rate * qty);
                    }
                   
                })
                $("#ctl00_ContentPlaceHolder1_TxtDiscount").blur(function () {
    
                    $("#ctl00_ContentPlaceHolder1_Label15").text(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) * parseFloat($("#ctl00_ContentPlaceHolder1_TxtDiscount").val()) / 100);
                        
                        $("#ctl00_ContentPlaceHolder1_TextBox2").val(parseFloat($("#ctl00_ContentPlaceHolder1_TxtAmount").text()) - parseFloat($("#ctl00_ContentPlaceHolder1_Label15").text()));
                        
                        var Tax = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val())
                         if (Tax < 1000) {
                        $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 5 / 100);           
                        }
                        else if (Tax > 1000) {
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);           
                        }
                        else{
                         $("#ctl00_ContentPlaceHolder1_TextBox5").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val()) * 18 / 100);        
                        }
                        
                        
                        var a1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox5").val());
                        var b1 = parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
                        var c1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
     
                       $("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text(a1 + b1);
                       
    //                   if (c1 < 0) {
    //                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(parseFloat($("#ctl00_ContentPlaceHolder1_TextBox2").val());
    //                   }
                       
                   $("#ctl00_ContentPlaceHolder1_TxtRO").blur(function () {
                        var k1 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtNet_Pay").text());
                        var k2 = parseFloat($("#ctl00_ContentPlaceHolder1_TxtRO").val());
                   
                   
                    $("#ctl00_ContentPlaceHolder1_Txt_Fin_Value").val(k1 - k2);
    
    })
    
                })
    
            }
    
    
    $( function () { //call the function after the page is loaded to bind event myFunction(); var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function (e) { // call the function here to rebind the event after updatepanel returns myFunction(); }); } ) </script>

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 23, 2018 3:29 AM
  • User-807418713 posted

    Thank You Ackerly Xu

    Friday, November 23, 2018 1:31 PM