Franc Stratton's .NET (TM) Web Application, OOP, and SOA Architecture & Programming Site

A site devoted to ASP.NET (TM), SilverLight (TM) and Browser-Based WPF (TM) Applications, IIS Services, and OOP Architectures

Home     .NET Security     Standards     Data Store     Windows Form Apps     WF/WCF/WPF     jQuery     C# Developer Corner     Java Development     Site Map      
jQuery Basics for ASP.NET
jQuery Selectors
jQueryEvents
Event Handler Methods
jQuery Special Effects
Simple Page Styling
jQuery Callbacks
jQuery Page Method
jQuery Data Method
Simple Dirty Flag
Advanced Dirty Flag
AJAX Call to Web Service
jQuery Callback Functions for ASP.NET Applications

 

As displayed earlier in jQuery Special Effects, many jQuery functions involve animations. These animation functions may take effect durationor speed of execution as an optional parameter value. For example:

 

$("#btnHideText").click(function(){
    $("#txtName").hide(2000);
});

 

Since JavaScript and, therefore, jQuery code statements are executed in a sequence line by line, instructions executed after a special effect may create errors  because the animation has been completed. To avoid this problem, a .NET developer can add a Callback Function as a parameter to the jQuery method. The jQuery callback function will be executed after the animation has completely finished. The form of the syntax usually is:

 

$(selector).hide(speed,callback)

 

In the case above, the callback parameter is a function executed after jQuery completes the "hide" special effect.

 

$(document).ready(function(){
  $("#btnHideText").click(function(){
  $("#txtName").hide(1000,function(){
    alert("The name text box is now hidden");
    });
  });
});

 

In the example above, when the button "btnHideText" is clicked, the "txtName" text box fades, and when it is completely hidden, the jQuery callback function displays the alert box message "The name text box is now hidden."