How to display loading GIF Image In JQuery AJAX in ASP.NET


Today’s JQuery is most powerful library for web development GUI customization. Hence I would write another great article about how to display the wait or loading GIF using JQuery with when you are call AJAX Load method. Let’s say you have to load list of state based on your selected country. In this scenario, we can use the AJAX Load with div element.

Now, let say we have to show the loading gif one we are select the country, then AJAX load has request to get the states content from the database. Here is followings steps will be happen internally

1. Something triggers AJAX request (select a country).
2. We put the loading image that asks for user patience to the place where we would later insert the loaded list of state list in the html element (div).
3. After remote content is fully loaded, the content will replace earlier div html by this new content.

Note: before start the demonstration, you have to download JQuery library from or you can point the Google JQuery API URL as well.

Now, design the page for load state list, when we select a country.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CountryDemo.aspx.cs" Inherits="WebApplication1.CountryDemo" %>

Note:I have used JQuery library from Google API.

What are the advantages of use Google JQuery URL ?

Here whole details for this question.

Now let’s write JavaScript code with JQuery library to load state once we select the a country

Through the above code ,when we are select a country, then change event will raise and send country ID to server page1.aspx.Within the page1.aspx, will compose the state list as html format, finally will write as response to client. But here now you can’t see any loading or wait GIF image when you are select a country from country dropdown list.

Let’s see, how to implement that, just an additional line we have to add within above script.

In above code, i have added only this line to load GIF.

Once change event raised, GIF loading image wild add into div inner content, Once content from loaded from the server page, then .load() function would replace our loading image indicator with the loaded content.The $('#mainContent').empty() will clear inner html of the div,and then when we are call $('#mainContent').empty().html() method will add new element inside the div.


here I have not give the sample project with article. because I have given core part of the implementation with this article. So I hope you able to catch and enjoy.

No comments:

Post a Comment

Keep ur coding aside.. Relax for some time..