How to call Jquery function from C#

后端 未结 3 547
萌比男神i
萌比男神i 2020-12-19 13:23

I would like to fadein and out a div after performing some code. This JQuery function is working fine when using the button\'s onclientclick property. But, Unable to call it

3条回答
  •  误落风尘
    2020-12-19 13:29

    When using asynchronous post backs is good to understand the events that you can actually handle on the client side (aspx file).

    If you want to execute some client function (jquery, javascript) after an asynchronous post back has been made, I suggest using the pageLoaded event on the client side. So your javascript will be something like the following:

    function pageLoad(sender, args) { 
        $(".saved").fadeIn(500).fadeOut(500);
    }
    

    For more information please refer to this MSDN page on the Event Order for Common Scenarios section.

    Hope this helps


    Edit after comment to add filter example

    To filter logic in the pageLoad event depending on the element that raised the event, as stated in this MSDN page, on the Animating Panels section, you can do something like this:

    var postbackElement;
    
    function beginRequest(sender, args) {
        postbackElement = args.get_postBackElement();
    }
    function pageLoaded(sender, args) {
        if (typeof(postbackElement) === "undefined") {
            return;
        } 
        else if (postbackElement.id.toLowerCase().indexOf('btnsave') > -1) {
            $(".saved").fadeIn(500).fadeOut(500);
        }
    }
    

提交回复
热议问题