August 2006 - Posts

Upcoming Talk for the San Diego .NET Developers Group
29 August 06 11:13 AM | Scott Mitchell

Next week - Tuesday, September 5th - I'll be speaking at the San Diego .NET Developer group. My talk starts at 7:00pm and will likely run until 8:30 or so. I'll be talking about Working with Data in ASP.NET 2.0, a sort of in-person, spoken and visualized complement to the Working with Data in ASP.NET 2.0 tutorial series I've been writing for Microsoft.

If you're in San Diego on the 5th, drop on by! The meeting is held in Sorrento Valley at one of Qualcomm's facilities, and it's probably the nicest LUG facility I've ever been to - free parking, incredibly nice plush stadium seating... it's like you're in the theaters, except the aisles aren't sticky and I'm not as dashing or exciting as Brad Pitt. But the biggest incentive is that there will be free pizza and soda!!

Hope to see you there!

Filed under:
Upcoming Talk at the SoCal .NET Technical Summit
24 August 06 07:28 AM | Scott Mitchell

On Saturday, September 23rd, I'll be speaking at the SoCal .NET Technical Summit in Irvine, CA at the Hilton next to the John Wayne Airport. I'll be doing a “Top 10 ASP.NET 2.0 Tips & Traps” talk, which makes me the biggest Scott Guthrie/Rob Howard fanboy (Scott recently presented an ASP.NET Tips and Tricks talk at TechEd in New Zealand, and Rob Howard's done a “Top 10 Tips for Writing High Performance Websites” talk before).

Anywho, the reason I'm posting this is two-fold. First, I want you to come to the Summit! Yes, I'm talking to you. Come on, go, it will be a day full of fun and educational value, with talks broken down into Architecture, Web, Data, and .NET 3.0 tracks. It's only $79 for the conference. Go ahead and register now.

Second, I'd like to get some feedback/suggestions on my talk. Here are my proposed Top 10 Tips & Traps:

  • TIP: Use HttpContext.Items as a per-request cache (stole this shamelessly from Rob Howard's performance talk, but it's my favorite of his)
  • TRAP: Not setting applicationName setting when using Membership (a trap many people getting started with Membership fall into)
  • TIP: A walkthrough of cool Visual Studio 2005 features (I'm thinking about some of the XHTML validation stuff, code snippets, opening an ASP.NET 2.0 website through the command line/Explorer, etc.)
  • TIP: Client-side enhancements (the new OnClientClick property, the Focus() method, etc.)
  • TIP: Efficiently paging through large resultsets with SQL Server 2005's new ROW_NUMBER() feature
  • TIP: Using Reflector (not really ASP.NET-specific, but a tool/knowledgeset every .NET developer should have)
  • TRAP: How to handle broken images/links in images, CSS files, etc. A common problem when using a Master Page in one folder and having ASP.NET pages in different folders. In short, use ~
  • TIP: Disabling view state for data Web controls to reduce page bloat
  • TIP: Use caching. An overview of data caching, output caching, and SQL-dependent caching
  • TRAP: Avoid race conditions when caching - see http://scottonwriting.net/sowblog/posts/1982.aspx

I'm a little wishy-washy on some of these, this list was what I came up with a couple days ago. Care to help me shore up this list? Any suggestions for tips/traps? Any tips/traps you'd prefer removed, or relegated to “Only cover if you have adequate time?”

Any suggestions, comments, ideas, and constructive criticism is most welcome. You can either post it as a comment here, or drop me a line at mitchell@4guysfromrolla.com

Hope to see you at the SoCal .NET Technical Summit!

Filed under:
Custom Paging and Navigating to the Last Page
18 August 06 09:46 AM | Scott Mitchell

My latest set of Working with Data in ASP.NET 2.0 tutorials focused on paging and sorting data and included a look at implementing custom paging (with sorting) with the GridView and ObjectDataSource. Alert reader Mark Fox pointed out that there's a bit of a problem when using custom paging and clicking the Last page link in the paging interface:

For lesson 25 – Efficient Paging I downloaded the file ASPNET_Data_Tutorial_25_VB.exe and than opened the project in VS 2005 Standard and ran PagingAndSorting/EfficientPaging.aspx. Clicking the PageLast >> button in GridView1’s pager gives a System.OverflowException in System.Web.UI.WebControls.GridView.CreateDataSourceSelectArguments().

Enabling the viewstate in GridView1 fixes this.

With custom paging, the page count value returned by the ObjectDataSource’s SelectCountMethod is stored in the GridView’s view state. Other GridView variables – the PageIndex, EditIndex, SelectedIndex, DataKeys collection, and so on – are stored in control state, which is persisted regardless of the value of the GridView’s EnableViewState property. Since the PageCount value is persisted across postbacks using view state, when using a paging interface that includes a link to take you to the last page, it is imperative that the GridView’s view state be enabled. (If your paging interface does not include a direct link to the last page, then you may disable view state.)

Clicking the last page link causes a postback and instructs the GridView to update its PageIndex property. If the last page link is clicked, the GridView assigns its PageIndex property to a value one less than its PageCount property. With view state disabled, the PageCount value is lost across postbacks and the PageIndex is assigned the maximum integer value instead. Next, the GridView attempts to determine the starting row index by multiplying the PageSize and PageCount properties. This results in an OverflowException since the product exceeds the maximum allowed integer size.

To see the problem in code, use Reflector and drill into the GridView's HandleEvent method. There you'll find a switch statement that handles the different types of events, one of them being when the last page link is clicked:

if (base.IsViewStateEnabled)
{
num1 = this.PageCount - 1;
}
else
{
num1 = 0x7fffffff;
}

So if view state has been disabled, then num1 (the page the GridView is going to try to access) is set to the maximum integer value (2.147 billion, roughly). Next, look in the GridView's CreateDataSourceSelectArguments() method, and there you'll find:

arguments1.StartRowIndex = this.PageSize * this.PageIndex;

That multiplication right there is what causes the OverflowException, as any PageSize value greater than 1 will result in a value that exceeds the largest possible integer value.

The fix? Enable view state in your GridView so that the PageCount property can be remembered across postbacks.

Filed under:
The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online!
15 August 06 05:57 PM | Scott Mitchell

Four new “Working with Data in ASP.NET 2.0” tutorials are now available online at www.asp.net. These four tutorials illusrate how to add paging and sorting capabilities to the GridView and ObjectDataSource, showing how to page and sort naively, as well as how to use the more efficient custom paging technique. There's also a tutorial on creating a more customized sorting user interface.

Like the previous 23 tutorials, these four are each available in C# and VB versions, can be downloaded as PDFs, and have their complete source code available for download as a ZIP file.

Check 'em all out - http://www.asp.net/Learn/DataAccess

Filed under:
September's Toolbox Column in MSDN Magazine
13 August 06 01:34 PM | Scott Mitchell

My ninth Toolbox column in the September 2006 issue of MSDN Magazine is now avaiable online. The September issue examines three products:

  • Fast-Help (version 4.4) - quickly and easily create help documentation that can be saved as WinHelp, HtmlHelp, PDF, Word, or web page-based help files.
  • FinalBuilder (version 4.1) - organize and manage your build process using FinalBuilder's intuitive user interface.
  • XHEO|Licensing (version 2.1) - protect your intellectual property by adding copy protection to your applications. With XHEO|Licensing, you can protect .NET applications using a variety of licensing schemes (serial numbers, online registration, and so on).

This month's issue reviewed Joel Spolsky's The Best Software Writing I anthology, which is a collection of essays pertinent to developers and project managers. It's quite similar to Spolsky's previous work, Joel on Software (which I blogged about earlier). Here's an excerpt from the review:

While the articles about computer science fundamentals, software design, testing, and project management are to be expected, there are also interesting pieces on topics secondary to actual development, but important to developers nevertheless. One essay, written by a developer's spouse, lambastes the short-sighted corporate policies instituted by her husband's employer; another ruminates on intellectual property rights and how it affects us all.

The title - The Best Software Writing I - rings with a tinge of hyperbole since the essays considered for inclusion were restricted to those written in the past two years. But all of the essays included were very interesting, well-written pieces. They range in length from a single page to over a dozen, but even the longer ones seem to end too soon. Joel's introductions to each essay also add color to the collection.

As always, if you have any suggestions for products or books to review for the Toolbox column, please send them into toolsmm@microsoft.com

You can keep abreast of the latest Toolbox articles through the column's RSS feed or the Toolbox column category here on my blog.

Filed under:
More Posts

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.