Follow these easy steps below to create your AJAX solution.
Start your Visual Studio 2005 IDE.
Choose Create Web Site from the menu.
In this sample application we will use the Visual Basic language for the
the solution UpdateProgressTest.
Choose ASP.NET AJAX Enabled Web Site.
Choose File System in the location box.
Click OK to create the project.
Visual Studio will create your project with a Default.aspx
page and probably a readme.txt. Go ahead and get rid of the latter file.
Open Default.aspx page in design view.
Manager control manages client script for Microsoft ASP.NET AJAX pages. By
default, the Script Manager control registers the script for the Microsoft AJAX
Library with the page. This enables client script to use the type system
extensions and to support features such as partial-page rendering and
your Toolbox you should find a new group called AJAX Extensions. Locate it and
see the controls in it.
drag two labels to the design area and write the text as it is shown in Figure
1. Do not forget to add a button.
Figure 1 - Simple application with Update Panel
click your form and write the code in listing 1 in the Form Load event.
Listing 1 - Code for the form load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = Date.Now
Label2.Text = Date.Now
the program. Notice that the labels are filled now with the current date and
time. Every time you click the button the time will change. Why, because the
code is the form load event.
let us get back to the design mode and add an UpdatePanel Control from AJAX
Extensions and drop it on the design page.
addition, move the second date line as well as the button into the UpdatePanel
as shown in Figure 1.
the program again. Please note that the two dates starts the same, but whenever
you click the button only the second date changes.
drag an UpdateProgress control from the AJAX Extensions tab and drop it wherever
you like on the web form.
the properties window of UpdateProgress control set the AssociatedUpdatePanelId
to UpdatePanel1 and set DisplayAfter to 1.
you to go to the source mode of the web page and add the lines in listing 2.
Listing 2 - HTML Configuration of the UpdateProgress
<ProgressTemplate>Refreshing the page.Please Wait
<img alt="Spinner" src="spinner.gif"></img>
any GIF animated picture, place it in the same directory as the project and
name it spinner.gif.
back to the Design mode of the form, double click the button and write the
lines provided in Listing 3.
Listing 3 - Code for the button click event
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Let us understand what happened and explain a little bit the
UpdateProgress control. When the code runs the web form contains the current
date as well as time on the screen. However, when the end user clicks the
button, the UpdateProgress control comes to the rescue and starts the sentence
provided in the progress template as well as the animated gif you have
provided. This action will continue for a period of 3 seconds as provided in
the sleep instruction. Please note that the sleep instruction should be
replaced with your real code.
Should you be more interested in making an elaborate
progress animation you could use a timer control (covered in the upcoming
article from the series).