Sacramento Software Development

What’s So Funny About the UpdatePanel Control, Love and Understanding?

Posted by John Lockwood on September 21st, 2009

I recently reported that I had a domain for an ASP.NET site to hack around on with nothing on it yet.  Since then I’ve made some progress and had some fun coding some ASP.NET, so I can now show off a minor feature on a new web site, the Featured ASP.NET Certification Question.

This isn’t exactly Google or even StackOverflow yet, to be sure, but there were nevertheless a fair bit of learning and practice goals along the way to this simple looking page. 

The Site and The Control

First, I ported the master page from this site, so that was worth remembering how to do.  Master pages can also expose properties to their content pages, which I haven’t done yet, but perhaps I’ll get into that when I add authentication to the site. 

The next steps were to set up a brain-dead and stubbed out custom control, ExamQuestionControl, while on the lower decks working out the database structure and connection strings for development and production and testing along the way using NUnit tests (Yes, Dan, NUnit Tests).  Once those were in place I began testing out the Plain Old CLR Objects and a simple, one method repository consisting of “QuestionFindByID”, which was all I needed at this point.  I implemented the repository using very basic (and hence certification-friendly) calls into the ADO.NET Connected Classes (one of which forms the basis for my first Featured Question).  Once NUnit had lifted the database up by its bootstraps, It was quite a simple matter to un-stub the formerly brain-dead ExamQuestionControl. 

Once the control was more or less working, I decided (as if setting myself up to take a look at the AJAX chapter) that I didn’t like the fact that the “Show Answer” button posted back the entire page to the server.  Microsoft’s UpdatePanel control provided an elegantly simple way to AJAX enable my control to avoid a full page refresh.  No seriously.  If your hatred of Microsoft is interfering with your Buddhist practice, sit still and contemplate the UpdatePanel control, and you’ll be filled with loving kindness.

Early Hiccups

In the earliest stages of the work, getting the hosting set up and so forth, I ran into a few noteworthy hurdles.  One was that I needed to compile the site and bin deploy the code-behind pages.  Other problems involved deploying an MVC site to godaddy.com, but as you can see from the link, a kind fellow traveler provided the solution.  Before I found that link, I had to re-code the master pages to inherit from System.Web.UI.MasterPage instead of System.Web.Mvc.ViewMasterPage.  Once I found that link, however, I was able to restore the ViewMasterPage with no problems.

What I would recommend to your attention when you get to the deployment phase of your project is to right click on your project and check out the “Publish…” menu option.  As others pointed out in the earlier link, the easiest thing to do turned out to be to publish to a local directory and upload files.  The link above shows you how to bin deploy MVC, and that trick no doubt works on other weird dependency issues.

Once I’d played with that a bit I decided to clean up what I’d originally uploaded, and noticed then that Visual Studio’s publish doesn’t copy over image files referenced in your CSS if you select the option to only copy what’s needed.  Copy those, end of problem.

image

Posted in ASP.NET, ASP.NET MVC | Add a comment »

Mixing ASP.NET and ASP.NET MVC in the same project – A Visual Studio Starter Project

Posted by John Lockwood on September 16th, 2009

There are lots of good reasons to dive into Stephen Walther’s ASP.NET MVC Framework Unleashed.  I won’t go into all of them now – perhaps I’ll write a review when I’m further into it.  My short recommendation is to go buy it, especially if you’re going to do so by clicking the link at the right, whereby I’ll make a whopping 29 cents or whatever it is.

And meantime, in a paradox that proves once again that information doesn’t always need to be perfect to be useful, I believe one of Walther’s weaker chapters (in terms of eloquence) was simultaneously one of his stronger chapters (in terms of usefulness).  This is the chapter on deployment, which deals (in part) with how you can add ASP.NET MVC to an existing ASP.NET application.  This was a really useful chapter in its broad outline, even if the layout of the file “diffs” left a lot to be desired, leaving some of the details a bit sketchy.  The short version is that you sit down for a couple of hours over coffee and merge files and add dependencies.

I used the information Walther provided to put together a starter Visual Studio 2008 project that allows you to use ASP.NET “classic” web forms together with ASP.NET MVC models / views / controllers in the same project.  (I also chose the unit testing option so there are tests built in).  I’ll try to do some more pounding on it before you read this, so it should be workable enough that the only thing you’ll want to do is rename all the namespaces and so forth from AspNetStarter to whatever you want to call your application.

Anyway, I hope you find it useful.  If so I put it together.  If not, I had nothing to do with it.  Here it is as a 389 Kb or so zip file.

Posted in ASP.NET, ASP.NET MVC | Add a comment »

Early ASP.NET MVC Troubleshooting

Posted by John Lockwood on September 6th, 2009

After happily switching between Visual 2005 and Visual Studio 2010 beta for several days, I installed Visual Studio 2008 recently so I could get started on ASP.NET MVC.  Well Hello World worked more or less without a hitch, but inside that “more or less” are two stumbling blocks I hit which I mention here in case anyone else stubs their toes in the same place:

 

  1. At first, the Visual Studio install didn’t work.  It turned out this was either a virus scanner or automated backup.  Turning both off as recommended in the Microsoft troubleshooting docs did the trick.
  2. The second little bit of trouble came when trying to create a new SQL Server database file in the App_Data folder to start playing around with something beyond Hello World.  For providing what appears to be the solution (still installing), and for coming up in first place in Google ahead of Microsoft, Pinal Dave is the winner of today’s gratuitous link to a solution.

 

Posted in ASP.NET MVC | 1 Comment »

Review of Stephen Walther’s ASP.NET MVC Framework Unleashed

Posted by John Lockwood on August 31st, 2009

This is a reprint of a review I did on Amazon.com.

I bought Stephen Walther’s ASP.NET MVC Framework Unleashed after several months of working on a legacy C and C++ project which looks nothing like Walther’s book.  Following that I spent many a happy Saturday and Sunday ramping up on Ruby on Rails, but finally giving up to revisit my Microsoft skills.  ASP.NET MVC is a serious attempt by Microsoft to lure wayward Ruby on Rails types like me back into the fold, and I consider myself re-folded.

Given my background, any halfway decent book on ASP.NET MVC would probably have been welcome, but Walther’s book is especially welcome because it makes a serious attempt to treat ASP.NET MVC in the context of Test Driven Development.  Well, all of that is what you’d expect if you take the cynical view that Microsoft is competing for developer mind share against Ruby on Rails, where the tests are "baked right in" (of course they all pass by default, but that’s another story).  But Walther’s book is far more than a cheerleading book about TDD, and actually gets you into how to structure your code to support it.  Using a generic repository class and relying heavily on the dependency injection pattern, Walther leads you through setting up your code so that it’s loosely coupled, testable, and (presumably) easily refactored.

Admittedly, it sometimes looks like Walther’s approach takes too much manual lifting compared to Ruby on Rails — and that’s especially true when you run into Microsoft annoyances like not being able to refresh an Entity Data Model from the database.  On the other hand, it’s hard for an experienced software developer not to take a skeptical view of the magical rails "we can build a blog in 15 minutes" approach to the world.  But still I feel that the techniques Walther talks about are the kind of thing that I really need to try out on an application or two.

I gave the book four stars because there were a few sections that I thought could have been explained better.  For example, I used his chapter on deployment almost immediately to create an application that supports both "legacy" ASP.NET and ASP.NET MVC, and the information there worked great, but I felt the file differences could have been narrowed down a bit more.  Also in his discussion of the generic repository, I felt like we lost sight of the model there for awhile.  Since there was a lot of ground to cover, a general overview discussing how the Entity Data Framework, the model, the repository and the service layer were all going to tie together might have been helpful.  My final quibble is that I felt there could have been a bit more material on the relationships among the Entity Data Framework, LINQ, and LINQ to SQL.  I think Walther’s book gave the impression that the EDF and LINQ are orthogonal, whereas other Microsoft sources lead me to believe they’re more complimentary.

Despite its flaws, however, I want to leave you with the title of my review, that this is one of the best programming books I’ve read in a long time.  It’s the kind of book that expands your horizons and makes you want to try things out the way the author has outlined.  To be sure, Walther’s book is not the book you want to read if you goal is to hack together an unstructured ASP.NET MVC application in record time.  But if your goal is to learn ASP.NET MVC while becoming a better programmer along the way, this book merits your serious attention and you should be pulling your credit card out now.

Posted in ASP.NET, ASP.NET MVC | 1 Comment »