Why is this page text-only?

Results tagged “AJAX” from Code Scene

Book Review: ASP.NET 3.5 Unleashed by Stephen Walther

A while back I posted a review of Stephen Walther's ASP.NET 2.0 Unleashed. It's a fantastic book that I've used more times than I can count. The release of the .NET 3.5 framework means there are lots of new things to learn. Thankfully, Mr. Walther has released an amazing follow up-book titled ASP.NET 3.5 Unleashed.

At 1890 pages this book has just about everything you need to know to start building complex ASP.NET applications. While the book assumes that you have some familiarity with using ASP.NET the first few chapters are still devoted to the basics. I encourage everyone to read them, even the experts. There are many tips and tricks in the book so you may learn something new or pick up on something you'd long forgotten. Did you know the asp:Literal control has a build in Mode property that can be set to HTML encode it's content? I'd honestly forgotten about that and had been doing my encoding on the back-end.

This book provides an in-depth look at just about all of the core ASP.NET features building on many of the techniques we used in 2.0. For the new features specific to ASP.NET 3.5 , Walther devotes an entire chapter to the new ListView and DataPager controls. These controls can be thought of as a GridView or Repeater on steroids. There's also a chapter on data access with LINQ to SQL and a 3-chapter section devoted to working with AJAX.NET and the AJAX Control Toolkit.

There are many books out there that focus on the "how" but what I like most about Mr. Walther's books is that he devotes a great deal of time to the "why". For example, the book explains how to use the SqlDataSource control but then also explains why you'll want to avoid it for most complex applications and use the ObjectDatasourceControl instead. With this book you'll not only learn how to get things done, you'll learn how to get things done right. For that reason it's an invaluable resource for your library. Every ASP.NET developer should have this book on his/her shelf.

Note: While the code samples in the previous 1.1 and 2.0 Unleashed books were written in VB.NET, this new 3.5 book has them written in C#. Walther cites the fact that there are now more C# developers than there are VB.NET developers as the reason for the switch. I would've liked to have seen two different versions of the book but all code samples are also provided in VB on the included CD-ROM so everyone can easily follow along.

Script.aculo.us Accordion and LightWindow

These days I spend more of my time in meetings and putting out fires than I do actually writing cool new bits of code, which is one of the reasons for the infrequent blog postings. Since I'm not writing as much code these days I can at least point out some of the cool work being done by other people.

Kevin Miller of Stickman Labs has provided two great components based on the script.aculo.us framework; Accordion and LightWindow.

Accordion is a great way to add collapsible panels where one panel closes as another one opens. This is a great way to organize pages which have lots of content, like a Frequently Asked Questions page or perhaps organizing some navigation elements on a page.

LightWindow is similar to Lightbox and other modal/pop-over window controls. It uses AJAX to pull content from the server dynamically and display it overlayed on top of the current page. What differentiates it from the rest is that it supports virtually any kind of conent. You can use it to load images, flash movies, video files, other HTML content, web forms, etc. It's easy to setup and there are lots of options you can tweak to make it work for your site.

Both controls can add cool functionality to your site and they're incredibly easy to install and use. Check them out and start enhancing your applications.

Lastly, people like Mr. Miller dedicate a lot of time creating projects like this for the rest of us to use. While he offers these free of charge, please consider supporting him and the community in general by making a donation. Hopefully this will encourage him to keep creating great work like this.

Code Scene: Greatest Hits

It's hard to believe it but it's been an entire year since I started the Code Scene blog. My goal was to catalog some of the tips and tricks I've picked up and share them with my friends, colleagues, and the web development community in general.

While I don't have as much time to dedicate to blogging as I'd like to, I hope that I've helped to contribute at least a little bit to the community I take so much from. For those of you new to Code Scene (and because I don't have much free time) I've compiled a list of my favorite articles from the past year.

Website Launch Checklist

Website Accessibility Checklist

The Problem with Content Management Systems – Part 1, Part 2

Search Engine Optimization

The Problems with AJAX

Missing the Point

Redirecting HTTP to HTTPS using IIS

Guidelines for Coding HTML Emails

The Design Triangle

Hopefully I'll have some more time in the next year to keep writing more of these. Until next time...

AJAX-Enabling a GridView Control with Atlas

In my last post, I pointed out some of the problems with AJAX. In this post, I'll show you to take the ASP.NET GridView control and AJAX-enable it in about 30 seconds using Microsoft's new Atlas framework.

The GridView control is one of the most powerful and commonly used components of the .NET framework. With it, we can easily display data from a datasource such as SQL Server and enable things like sorting, editing, paging, and deleting. All of this can be done with little or no code. Every time you execute a GridView function (such as switching pages) a postback occurs and the entire page reloads. Wouldn't it be great if we could update the GridView dynamically without the need for a postback every time?

The Atlas framework makes this not only possible, but extremely simple.

Step 1 – Download and install the Atlas Framework

Step 2 – Create a new Atlas project and make a new web form with a GridView control bound to a datasource. The Northwind database will work well for this.

Step 3 – Add an Atlas ScriptManager Control to the page and enable partial rendering.

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />

Step 4 – Surround your GridView control with an Atlas UpdatePanel conrol.

<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>
      <asp:GridView ID="GridView1" runat="server" ... />
   </ContentTemplate>
</atlas:UpdatePanel>

Step 5 – Save it. Run it. Marvel at how simple that was.

The Problems with AJAX

AJAX is the latest industry buzz-word and to hear people talk you'd think it'd have to be the best thing since sliced bread. I'll go on record as saying that I think AJAX is awesome but, since every other article touts how amazing it is, I'd like to play devil's advocate and point out a few of it's flaws.

JavaScript - AJAX functions entirely by using lots of client-side JavaScript to send requests to the server and update data on the page. No JavaScript means that none of your cool functionality works at all. Providing a non-AJAX alternative may require a lot of extra work.

The Back Button - This is fairly similar to what happens with Flash sites. The user does something, does something else, then wants to return to the previous task so they click the back button. When you're serving normal HTML pages this works great. In an AJAX application however, the back button is essentially rendered useless.

Analytics - Having standard HTML pages provides an easily mechanism to track what your users are doing. AJAX slightly complicates this by replacing some of the pages with asynchronous JavaScript calls. While not impossible, it does have the potential to add a layer of complexity to capturing analytical data. I should note however, that there are companies such as Crazy Egg that are actively working to solve this problem.

Accessibility - Having pages that rely heavily on JavaScript and updating dynamically has the potential to wreak havoc on screen reader type programs for users with visual impairments.

Search Engine Optimization - At this time it may be difficult for search spiders to properly index content returned through complex AJAX updates.

Pasting a Link - The page updates frequently but the address bar never changes. When you cut and paste the link to your buddy, they just see the homepage instead of the info you intended. (Google Maps solves this nicely with a 'Link to this Page' button that updates the URL)

I'm certainly not trying to discourage AJAX use as none of these issues is insurmountable. As with all new technologies however, I would encourage caution and careful consideration before deploying. It's important to understand why you're using the technology instead of using it just to brag that you built an AJAX site. Remember when everyone had to have an all-Flash site, or crazy DHTML? That was the cool thing to do but people quickly learned that it wasn't always the right thing to do. I would urge people to remember that lesson and use the same caution here. AJAX is a fantastic technology and can be greatly beneficial when used properly. Let's do our best to ensure that it stays that way.

I'm out of town for a few days but after that I'll be back with some code samples on how to do some pretty neat things using ASP.NET 2.0 and Atlas.

AJAX - A paradigm shift

Hearing about all the new AJAX functionality that Microsoft’s Atlas allows us to easily implement got me thinking about how to effectively leverage it.

While most of the improvements to ASP.NET, Visual Studio, etc. enable us to do what we’ve been doing faster and more efficiently, AJAX really changes the game by altering the very foundation on which we build website applications.

The OLD Way – Submit Forms / Receive Pages
The NEW Way – Submit Requests / Receive Data

What this means is that we can selectively update portions of the page without causing the entire browser to refresh (a postback), effectively making the web run much more like a desktop application. This functionality provides for better user interfaces and richer client experiences.

Thanks to frameworks like Atlas, much of the technical hurdles can be easily overcome but there’s another underlying problem. How do we design, architect, or wireframe for AJAX-enabled sites? A typical design or wireframing process involves mapping out each page in the site and defining what types of content it contains. What happens with AJAX however, is that portions of the content, site functionality, and elements requiring user interaction can now take place without the need for a separate page.

In my humble opinion, this represents a new way of thinking and a significant shift in the way we approach building a site. As developers on the cutting edge of employing this new technology I think it’s also part of our job to work with the designers and architects to figure out the best way to create the user interface using all of the tools we now have at our disposal.

DevConnections - Day Four

I'm posting this from the Orlando International Airport which apparently has free wireless internet access. That's just fantastic. DevConnections is officially over. Here's my take on the last day.

Session 1 - Managing Memberships and Roles
One of the things ASP.NET 2.0 was designed for was to increase productivity and save developers time. To that end, Microsoft has added a suite of controls and components that allow for easily setting up login forms, creating users, managing permissions, etc. These components and methods take much of the work out of some of the more tedious tasks such as hashing password values, enforcing password creation rules, and locking users out after too many failed login attempts.

Since most of us will be using this with the SqlMembershipProvider for storing the data in SQL Server, it should be noted that by default, this is setup in Visual Studio to work with SQL 2005 Express. For use in a production environment with a full version of SQL, you'll need to prep the database first. There's a utility called aspnet_regsql.exe included with Visual Studio that will do just that. It can be run from the command line or there's a nice GUI if you run it in Windows.

The presenter, Bill Evjen, is also a member of INETA.org, which is an organization of Microsoft user groups that can be a great asset to continue learning.

Session 2 - ASP.NET 2.0 Essentials for building Professional Websites
This was a decent if somewhat repetitive session, which seemed to just recap some best practices from earlier sessions such as:

  • Use master pages to control page templates.
  • Create user controls to reduce complex and duplicated code
  • Plan for localization when you build your site so it's easy to add in later if needed
  • Always provide custom error messages to your users. Use the global.asax to create a custom error handler to log errors and/or alert administrators.
  • Design and test a caching strategy to improve overall site efficiency.

Session 3 - The Atlas Application Framework
More good stuff on Microsoft's new AJAX-enabling framework for ASP.NET 2.0 by Dino Esposito. This session contained a lot more technical information that I don't have the space to recount here. I plan on trying out a lot of the Atlas demos in the coming weeks and will post some more in-depth info at that time. This is pretty bleeding-edge so I recommend that anyone who's interested simply download the Atlas framework and start playing with it.

Session 4 - Improving .NET Application Performance and Scalability
There is always a bottleneck. Find it. Remove it. Repeat.
That was the overall message of this last session of the conference. For any application that manages data and/or supports multiple users, tuning your application for performance should play an important role. Here are some good tips and tricks:

  • Minimize round trips for data. Write stored procedures that retrieve multiple recordsets rather than running multiple queries
  • Acquire late - release early - open your connection at the last possible moment and close it immediately after you're done. In most cases it's better to have multiple open/close statements than it is to open it once, do all your processing, and close it at the end. ALWAYS make sure to close your connections, SqlDataReaders, etc.
  • Put the processing closer to the resources it needs - If you need to sort or filter data, do it in SQL instead of returning a large recordset and doing it in code
  • Defrag and rebuild database indexes regularly
  • Use the StringBuilder class for string concatenations within loops

Parting Thoughts
I am exhausted. I've crammed more new information into my brain in the past four days than I have in the past four months. Although very tired, I'm also extremely encouraged. With tight budgets and tighter deadlines, often the emphasis is on getting the project done and not necessarily on getting the project done right. Conferences like this provide a great venue for developers to learn in-depth details about the new technologies being offered and how to effectively utilize them. I have several projects coming up this summer that should be able to take advantage of things like Atlas, localization, fragment caching, and web parts. The knowledge I learned this week should help prevent a lot of late nights in the office and allow me to catch up on something I've been missing for a while... sleep.

DevConnections - Day Two

The morning started with keynotes touting many of the new and improved features of Visual Studio 2005. You can find some good demos, as well as a sneak-peak at the new ad campaign at www.400plusdifferences.com. After that it was off to the individual sessions...

Session 1 - Creating Dynamic Web Sites with ASP.NET 2.0 Web Parts
Web parts are a set of new controls in ASP.NET 2.0 that allow us to provide users with flexible display options and personalized content. The most common application of this interface would be for portal-type sites like MyYahoo and Google's personalized homepage but you can really leverage this technology for any kind of site.

The best part about web parts is that they work with existing ASP.NET controls and custom user controls with little or no effort. Just by dragging some controls onto the page you can quickly and easily give your users the ability to personalize the content. This could be a great feature for allowing your users to customize the homepage of any database-driven web application. By default the controls integrate seamlessly with Microsoft SQL server to persist data for authenticated users but that can also be modified to use any data store such as Oracle, MySQL, or XML.

Note: The drag and drop functionality to customize the display parts will only work in Internet Explorer at the moment but there are controls in the new Atlas framework that enable it for other browsers such as Firefox and Opera.

Session 2 - New Enhancements for Web Developers in Visual Studio 2005
This was an informative albeit sales-pitchy session about the improvements made to VS2005. My team has already been using VS2005 for a couple of months so a lot of the information I already had, but here's a quick breakdown of just a few of the cooler new features:

  • Built in development server. No need to have IIS installed
  • Better integration with SourceSafe for versioning and code control
  • WYSIWYG DataSet designer
  • Customizable tag formatting options
  • Better Intellisense
  • XHTML and 508/WCAG compliant code and built in validators

Another thing I should point out is that Microsoft has also released Visual Web Developer Express along with SQL Server 2005 Express. Both products are free to download and provide a great platform for developers to test-drive and learn ASP.NET 2.0 and the Visual Studio environment without having to plunk down hard-earned cash.

Lunch
I didn't plan on blogging about lunch but I had the pleasure of eating with Microsoft guru Joe Stagner who happens to be an exceptionally nice guy. We chatted a bit about Microsoft and general development stuff and he also pointed me to The Code Room, which is a "1/2 hour internet TV show that exposes technologists to the latest tools and technologies for tackling real-world software development issues". He wrote and produced an episode in Las Vegas last December that's worth checking out.

Session 3 - Using Visual Studio Team System to Build Enterprise ASP.NET Web Applications
Visual Studio Team System is a new version of VS that enables project management and collaboration functionality right within the developer environment. It also integrates directly with Excel, Project, and SharePoint to allow multiple developers and project managers to work together. While it seems useful for large teams working on an enterprise-sized project, I can't envision it being all that helpful for smaller web apps. They system is divided into parts for system architects, developers, and testers. Most of the developers I know (myself included) usually get stuck doing all three so this almost seems more bother than what it's worth.

One part I did find especially interesting however, was the testing features available for web applications. You're able to simulate any number of incrementally increasing users using multiple browsers to effectively stress test your applications before deployment.

Session 4 - An In-Depth Look at Building Enhanced Web Apps Using Atlas
By far the biggest draw so far, the Atlas session was packed with people standing and sitting in the aisles. For good reason it would appear. Atlas seems to be the most interesting surprise in Microsoft's bag of tricks.

Atlas is a cross-browser JavaScript library and server-side assembly that provides AJAX functionality on top of ASP.NET 2.0. The most impressive part about it is that it enables AJAX-style partial-page rendering without a lot of work and without having to write any complex JavaScript. The coolest part for me was the ability to extend existing controls within the framework such as adding drag and drop functionality or auto-complete for textbox controls.

Session 5 - Cool Tips & Tricks in ASP.NET 2.0
The day concluded with a session by keynote speaker Scott Guthrie who is not only brilliant but also a great presenter. It was designed to provide 10 tips and tricks to help increase overall productivity and it was exceptionally beneficial. I won't bother to recap the tips and tricks Mr. Guthrie provided since he's made them available on his blog. I highly recommend downloading this session.
ASP.NET Connections Tips and Tricks Slides+Demos Posted

DevConnections - Day One

Right now I'm down in beautiful Orlando, FL for the 2006 Microsoft DevConnections conference that my company was gracious enough to send me to. Today was day one and I just returned from the reception and keynote speeches by Scott Guthrie and Matt Nunn. Both speakers were excellent and I'm looking forward to the sessions tomorrow.

There's a ton of stuff going on during the next three days but I'm going to concentrate on the ASP.NET track. It looks like one of the more interesting topics is going to be "ATLAS", Microsoft's new framework for implementing AJAX functionality in ASP.NET. Mr. Guthrie did a brief demo of it during the keynote and it looks very impressive. With just a few lines of code, he took a DataGrid with paging, sorting, edit, and deleting, and made the whole thing AJAX-enabled. It looks both easy and powerful, and best of all it's free. You can download the Atlas framework from the asp.net site and try it out.

One of the more interesting things I found out was that the popular social networking site MySpace.com is running on ASP.NET 2.0. MySpace ranks as the #2 most popular site on the Internet (Yahoo! holds #1) with 1.5 billion page views per day. That's some serious traffic. Later this month they plan to role out a new profile personalization engine using Atlas so that'll be something to look for.
More info on how MySpace takes advantage of Microsoft technology.

There're conference sessions and events from 7AM until 9PM tomorrow so I'll hope to have some more good info to report then.