Tips, tricks and all the info about Microsoft Visual Studio 2008

Using AJAX and ASP.NET Extensions with .NET 3.5 & Visual Studio 2008

, posted: 18-Mar-2008 09:00

One of the many new features of Visual Studio 2008 is built in Support for ASP.NET AJAX development. Previously with Visual Studio 2005 you would have needed to download separate add-ons and project templates in order to AJAX enable your web applications.

This becomes much easier with Visual Studio 2008’s built in support for AJAX development and the .NET framework 3.5.

By creating an ASP.NET website or web application Visual Studio 2008 will automatically add the required configuration settings for AJAX in your web config as well as the AJAX controls.

AJAX Project Templates
When you open Visual Studio 2008 to create a new web site/application you will see the following templates



As you can see above those templates include the ASP.NET Web application template which will allow us to setup an AJAX enabled web application project as well as the following two new templates:

- ASP.NET AJAX Server Control
- ASP.NET AJAX Server Control Extender

The above two controls differ from the ASP.NET Server Control in that they are associated with JavaScript files and allow you map server control properties with JavaScript file properties.

In addition the difference between the ASP.NET AJAX Server Control and the ASP.NET AJAX Server Control extender is that the AJAX Server Control has its own JavaScript associated with it when you build the control but the AJAX Server Control extender allows you to add AJAX/JavaScript functionality to existing controls.

Project Files for ASP.NET AJAX Server Control & Server Control Extender
The screenshots below show you the project files included for both types of the above projects.

ASP.NET AJAX Server Control



ASP.NET AJAX Server Control Extender


If you closely examine each of the content of the project files below you will notice that they are almost identical despite the name differences. However, they are different. With the AJAX Server Control when the GetScriptDescriptors() method of the behaviour class is called it is passed the client id of the custom control as seen below.



But in the case of the Control Extender we pass the client id of another control



You can find additional information about AJAX Server Controls and Control Extenders in the articles ASP.NET AJAX Controls and Extenders Tutorial and Adding ASP.NET AJAX Client Behaviours to Web Server Controls.

AJAX Extensions Built In Support
As mentioned earlier, when you create a new web application in Visual Studio 2008 it will be AJAX ready by default and there is no need to download the AJAX extensions as was the case in Visual Studio 2005. When you open the tool box in Visual Studio 2008 you will automatically have the AJAX extensions as shown below.



Microsoft AJAX Library
The Microsoft AJAX library which can be found on the AJAX downloads site mentioned earlier is a new library that provides you with JavaScript resources for ASP.NET AJAX client components in ASP.NET 3.5.  The library is mainly intended for situations where you want to build AJAX applications on any platform and any server based technology such as ColdFusion and ASP.NET.

ASP.NET Extensions 3.5 Preview
Another area of new features that you can use with Visual Studio 2008 and ASP.NET AJAX is the ASP.NET 3.5 Extensions which you can download from the AJAX downloads page. When you install the AJAX extensions you’ll see some new project templates such as those for creating ASP.NET MVC applications and Dynamic Data Web applications.



From the list of projects above when you choose the ASP.NET 3.5 Extensions web application template you will see the following extra section of new controls that you can use in you applications including things like SilverLight and the new ListView control.



More information on those controls and how to use them can be found on the ASP.NET 3.5 Extensions Quick Start tutorials page.

One very interesting control in the list of the new controls above is the new ListView control and the reason for that is that it gives you complete control over the generated HTML mark-up. For more information on how you can use the new ListView control along with some other of the extensions preview controls see Scott Guthrie’s post on how to build a product listing page with clean CSS.

Calling Web Services from Client Script in ASP.NET AJAX
Another really great feature with .NET 3.5 and ASP.NET AJAX is easily being able to use client side code to execute server side logic and display results on your ASP.NET page.

This is a great feature that can be very useful when you are not using server controls and what to add some AJAX functionality to your website while being able to use some server side code. This is somewhat similar to what you can do with the AjaxPro library but is baked into the .NET framework. This can be done in three easy steps!

- Create your web service function and declare the web service as a script service
- Configure your application in web config to allow calling a web service from a script
- On your web page register your web service with the script manager and write two JavaScript methods one to call your web service and one to obtain the web service result and display on the page.

The article Exposing Web Services to Client Script in ASP.NET AJAX explains how you can do this in detail.

Download Visual Studio 2008 90 day trial
For detailed information and to request a free 90-day trial DVD of Visual Studio 2008 Team Suite to be sent out to you, go to the Microsoft Visual Studio webpage.

About the Author
Daniel Wissa is a Web Developer working in Christchurch. He has a B.Com. from the University of Canterbury where he studied Information Systems and Computer Science and is also a MCAD in .NET.

He has been involved with Microsoft and Microsoft communities for many years since being a Student Partner at Canterbury University a few years ago to currently leading the Christchurch .NET user group. He also maintains a blog
http://www.dan.net.nz where he regularly blogs about Microsoft technologies, local user group events and more.



Other related posts:
The New Zealand ALM Conference 2011 (Application Life Cycle Management)
Writing your own Html Helpers for the ASP.NET MVC Framework
Automating Visual Studio 2008








Comment by Claudio Sanchez, on 10-Apr-2008 07:17

Excellent article to be used as guid and reference for the new VS 2008 templates. Keep up the good work Claudio


Comment by sangam, on 25-Jul-2008 18:14

I liked the post. So many confusions could exist with the new release of visual studio. Posts like this help programmer a lot. Thanks again!


Comment by Gnosis, on 6-Aug-2009 19:16

How to add AjaxExtensions to an existing project ?


Comment by Manoj, on 18-Sep-2009 04:36

Hi , I have installed visual studio 2008 professional edition and when i try to add a new website i dont see any of the Ajax enabled website in the window. I also notice that there is no AJAX Toolkit installed in VS2008 . Do i need to follow any more steps. I have installed visual studio completely . Please Help.....


About the Visual Studio 2008 Blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce over 250 new features in the 2008 release.

This sponsored blog will bring Visual Studio 2008 tips and tricks from well known developers in the Australian and New Zealand tech community directly to you.

Make sure you bookmark this blog or subscribe to our RSS feed.



Other blog posts

The New Zealand ALM Conference...
Writing your own Html Helpers ...
Automating Visual Studio 2008...
Windows Azure Table Storage - ...
Windows Azure Table Storage - ...
XML and XSLT in Visual Studio ...
Introduction to New SQL Server...
Using the Visual Studio 2008 P...
Getting started with Windows A...
Why consider sitting for an MC...


Some recent comments

Praveen M on Visual Studio 2008 support for building SilverLigh: I installed SILVERLIGHT TOOLS for VS2008 at my work. I am able to do silverlight...

zefo on Unit testing with Visual Studio 2008: Just minor recommendation: better use *.png for the screenshots. Jpeg is more su...

gil ziny on Unit testing with Visual Studio 2008: When I associate the unit test with TFS testing policy, if fails during check-in...

lynette on Visual Studio 2008 JavaScript Debugging: i have enable in IE the ability to debug scripts. if i go to my section in my c...

Junkie on Why consider sitting for an MCTS or MCP Certificat: The way you presented the case for certification has been completely different f...

Brian Link on Unit testing with Visual Studio 2008: You seem to be incorrect in one of your opening remarks - it seems that web.conf...

Dipanwaya on Unit testing .Net Compact Framework applications w: Steps Behind the Test in the VS 2008? How to test a module in the VS 2008 Envir...

Ricardo on Visual Studio 2008 support for building SilverLigh: Yes! Found the solution myself :) Reset the environment of Visual Web Developer...

Ricardo on Visual Studio 2008 support for building SilverLigh: Have the same problem after installing Visual Web Developer 2008 SP1 and Silverl...

kjward on Automating Visual Studio 2008: thanks lots for all the great info. i'm sure the answer to my question is in th...



Disclaimer

The Visual Studio 2008 blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio 2008 and are not influenced or filtered by Microsoft NZ in any way.