July 2009 Entries

About the Author (me)

I thought I’d write a little “about the author” regarding myself, since I just recently opened this blog in this community. I work pretty much exclusively in ASP.NET ,using C# as my preferred language. Something about no curly braces really weirds me out in code…It seems unnatural. (: I’ve been working with and enjoying computers my whole life, so it only made sense to make it into a living. I work for a start-up company that I helped co-found and I do some freelance work on the side. I’m also working ......

Tutorial: Paging with LINQ and ObjectDataSource

I’ve read a few tutorials online about paging with LINQ and an ObjectDataSource but there were always quirks that ended up slowing me down unnecessarily so I thought I’d put together my own easy to follow tutorial that should get someone up and running with paging in almost no time! Step 0: Things I will Assume about your Project I’ll assume that you have already created a DataContext and dropped in some tables from your database onto it. For my tutorial, I’ll again re-use the “Person” object that ......

Quick Tip: LINQ OrderBy and ThenBy

The other day I required ordering a list of people first by the date they were created, and then by their last name. I spent forever trying to find out why my two OrderBy statements were conflicting with one another, until I remembered you use “ThenBy()” for any additional sorting you want to do. So the query looked something like this then: IEnumerable<Person> myPersons = myDataContext.Persons .OrderBy(m=>m.DateCreated) .ThenBy(m=>m.LastName); Just thought I’d share! It’s easy to forget ......

Tutorial: ListView ItemDeleted, ItemUpdated and ItemInserted Events

When it came time to start catching and handling exceptions in my program, I had never thought to use the events for ItemInserted, ItemDeleted and ItemUpdated for the ListView. They are incredibly useful. The events arguments passed as the second parameter expose some very useful properties that let you manage exceptions, access previously entered values and more. I’ve created a ListView and gone ahead and created the three events attached to it. Below you can see that the Intellisense has brought ......

Tutorial: Why the ObjectDataSource is my best friend

So when I first started working with SQL Server 2008 and LINQ, I would pretty much just use the LinqDataSource because it was definitely the easiest to use. It’s pretty good for testing purposes, or really small projects, but if you’re doing anything that is going to grow / is large already, then you’ll probably not want all that logic embedded in your pages. As I became more comfortable with LINQ, I decided to take on the task of switching over to the ObjectDataSource to bind to my ListViews. Here’s ......

Tutorial: Implementing/Working with Class Libraries

It was about 2-3 months into working with .NET that I finally realized the amazingness that are class libraries. It was one of those things that I knew would be useful, but I could never really find a great explanation for how to get them to work and how to easily pass them around multiple projects and update them, etc. I’ll write the post as if I’m working through the process: So the basic part was easy. I have my web application and it has a ton of files in App_Code folder. I want to move them ......

“Seriously? It’s that easy?” Episode 1: Generic Interfaces

So this is episode 1 of a series of blog posts I will be writing on things I could not figure out for the longest time, only to have an “ohhh moment” followed by a “seriously? it’s that easy?” moment. The first moment I will be describing occurred to me about a month or two ago when I finally understood how to use a generic interface. I had sort of captured the idea of interfaces by that point—that it’s basically like a binding contract that says ,if you implement me in a class, then you are required ......

ListView extension I thought I’d share…

I use the ListView pretty much exclusively for all my databinding needs, because, well, it does everything. One of the common things I do over and over in my backend is something like this: myListView.DataSource = myDataSource; myListView.DataBind(); I wanted to basically set the datasource, and bind it all in one line of code (because I’m lazy). So I wrote up this extension method: public static ListView QuickDataBind(this ListView myListView, object myDataSource) { myListView.DataSource = myDataSource; ......

Fixing “Row not found or changed” LINQ error

So over the past few months I have hit so many bugs and errors coding in .NET, that I thought I’d share a some of them that I spent several hours trying to fix, only to realize it was a simple solution. This will be a multi-part series, if all goes to plan. LINQ Error: “Row not found or changed”. This one took some head scratching. It’s a pretty generic error, and unfortunately the internet wasn’t of great use to finding the answer. I use timestamp columns in almost every table, since it makes updating ......

Viewstate: Friend or foe?

So I’m pretty sure I’ve read about a thousand articles regarding ViewState and whether or not people should enable it on every thing, ever, or go ahead and disable it on the page level as the second thing you do after creating a new .aspx page. I’ve been working with .NET now for about seven months and started out pretty much letting viewstate do its default thing. It seemed great. I didn’t really notice any performance hits so I just kept doing it. Now that the application has grown significantly ......

Beware of nested web.config theming…

So I have recently implemented dynamic themes and master pages for the program I’ve web program I’ve been writing this year. I had noticed something peculiar after publishing the updates to my live server. When I published it as a precompiled DLL (that did not allow updates), the theming worked just fine. The user would log in, select their theme (currently supports two) and it would render every page fine. When I published it using X-copy, one page would render as a mash up between the two themes. ......