Monday, May 05, 2008

ASP.NET 3.5

My last two major projects were in ASP.NET 2.0. That was just few months back. Now I am getting swamped in the .NET 3.5 world with WPF, Silverlight and LINQ and was bit worried when I had to consider ASP.NET as an option for a new project. By all chance, few months is longer than enough for Microsoft to flood us with new technologies and I was almost sure the new ASP.NET 3.5 will yet again look like an odd world for me.

But that was not the case. As with the .NET framework, the ASP.NET 3.5 is a set of additive features on top of ASP.NET 2.0. Most of the things I have learned in .NET 3.5 like the cool new C# features (LINQ, Query Expressions, Lambda Expressions, Type Inferencing (var), Class and Collection Initializers, Anonymous Types, Extension Methods) are useful in the web development world too. Moreover the new Visual Studio 2008 features (improved web page designer, css editing, javascript intellisense and debug support) are also much helpful for web developer.

Besides that there are very few ASP.NET specific new features. That includes ListView Control, DataPager control, and the integrated ASP.NET AJAX support.

ListView control is a beautiful data web control that can be bound to multiple records (like a grid) but still allows flexible layout. The DataPager only works with ListView Control and provides a paging user interface - next, previous, first, last buttons, for example.

AJAX support was earlier available in ASP.NET 2.0 as a separate download. Now it is part of ASP.NET 3.5. But if we want more AJAX controls, we still need to download the AJAX Control Tool Kit. You can unzip the contents to your computer (Somewhere like C:\Program Files\AjaxControlToolKit) and add them to Visual Studio. Make sure that the AjaxControlToolkit.dll is available in the Binaries folder. If not, you can either build the solution or copy it from the SampleWebSite's bin folder. By right clicking on the Toolbox in Visual Studio 2008, you can Add a new Tab and then Choose Items to browse for AjaxControlToolkit.dll to add all the AJAX controls into the tool box.

I did a sample AJAX website in few minutes. As usual start a new 'ASP.NET Web Application' project and make sure the target version of .NET Framework is 3.5. First we need to add the 'ScriptManager' and 'UpdatePanel' controls from AJAX Extensions tab in Toolbox and then we can add the controls to this panel. Try adding a Text Box, a Button, and a Label. On the designer, double click on the button to get the click event handler in the code behind. Change the label text to display something. (Label1.Text = "Hello " + TextBox1.Text;).



On the designer, an adorner appears on the supported controls and it can be used to add AJAX extenders. I tried adding a Confirmation Button Extender for the button and all I had to write was the ConfirmationText for this extender.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<cc1:ConfirmButtonExtender ID="Button1_ConfirmButtonExtender" runat="server"
ConfirmText="Are you sure?" Enabled="True" TargetControlID="Button1">
</cc1:ConfirmButtonExtender>

On running the application, a confirmation message box will appear while clicking this button, and the click event will be fired only after user confirmation. All this code will run at client side and the beauty is that I didn't write a single line of javascript.

Try adding PasswordStrength and DropShadowText extenders for the text box and have fun exploring more.

No comments:

Post a Comment