Follow the 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 UpdatePanelTest.
Choose ASP.NET AJAX-Enabled Web Site.
Select Visual Basic from the File System
Click OK to create the project.
Visual Studio 2005 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.
You noticed that
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 without the Update
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 Update Panel Control from AJAX
Extensions and drop it on the design page.
addition, move the second date line as well as the button into the update panel
as shown in Figure 2.
Figure 2 - Simple application with UpdatePanel
the program again. Please note that the two dates starts the same, but whenever
you click the button, only the second date is changing now. You will also
notice that the page does not refresh each time you click the Button control.
Let us understand what happened and explain a little bit the
UpdatePanel. When the code runs without the UpdatePanel and there is a post
back event, form load will execute and change the contents of the two labels to
the same date and time. When the update panel was introduced the date label as
well as the button were included it. So simply speaking, now the button will
only update the controls that are within the update panel borders since it is a
part of it.
Therefore, only a part of the page was sent back to the
server and the controls inside the Update Panel were refreshed. We have solved
our problem stated above and had fun doing it without even a big effort.