Using ASP.NET AJAX C# Help

Now that you have seen the component parts of ASP.NETAJAX,it is time to start looking at how to use them to enhance your Web sites. In this section, you see how Web applications that use ASP.NETAJAX work, and how to use the various aspects of functionality that ASP.NETAJAXincludes. You start by examining and dissecting a simple application, and then add additional functionality in subsequent sections.

ASP. NET AJAX Web Site Example 

The ASP.NET Web Sitetemplate includes allthe ASP.NET AJAX core functionality.You can also use the AJAX Control Toolkit Web Sitetemplate (once installed)to include controls from the AJAX Control
Toolkit.For the purposes of thisexample, you can create a new Web sitethat uses the default ASP.NET Web Sitetemplate in the c. \ProCSharp\ directory,called PCSAjaxWebApp1.· Modify the code in Defaul t .aspx as follows:

Switch to design view (note that the ASP.NET AJAX controls such as UpdatePanel and UpdateProgress have visual designer components), and double-click the Calculate button to add an event handler. Modify the code as follows:

protected void GoButton_Click(object sender, EventArgs e)

Save your moditications and press F5 to run the project. If prompted, enable debugging in Web. config. When the Web page appears as shown in Figure 39-2, note that the two render times shown are the same.

Figure 39-2

Figure 39-2

Click the Calculate button to display prime numbers less than or equal to 2500.Unless you are’ running on a slow machine, this should be almost instantaneous. Note that the render times an! now different – only the one in the UpdatePanel has changed. This is shown in Figure 39-3.

Figure 39-3

Figure 39-3

Finally, add some zeros to the maximum value to intreduce a processing delay (about three more should be enough on a fast PC) and click the Calculate button again. This time, before the result is displayed, note that the UpdateProgress control displays a partially transparent feedback message, as shown in Figure 39.

Figure 39-4

Figure 39-4

While the applicationupdates, the page remains responsive.You can, for example, scroll through the page. Note thot whtn the update completes, the scroll position of the browser is setto the point it was at before you clicked Calculate. In most cases, when partial-page updates are quick to execute, this is great for usability.

Close the browser toreturn to Visual Studio.

Posted on November 2, 2015 in ASP.NET AJAX

Share the Story

Back to Top