Saturday, September 02, 2006 7:33:50 PM UTC :: Filed Under ASP.NET | C# | Web Design

When trying to test a long web form, it gets really annoying having to manually populate the form with information only to submit the form to see your error and then have to do the whole thing over again once you think you’ve fixed the problem.

Since I don’t own a copy of Visual Studio .NET 2005 Testing Edition, I haven’t had much luck with finding good ways to test the UI (i.e., good ways to pre-populate forms for testing.) Of course, one way to test a form is to actually set all the values in a form on the ASPX page and then hope you remember to delete all those values once you publish the site. However, this becomes very annoying if you don’t get things right the first time.

To make my life easier and make UI testing less painful, I came-up with a nifty way to "cheat"... I’ve started using conditional compilation to populate my forms when Visual Studio is in DEBUG mode, but leave the forms blank when in RELEASE mode. So far, it works pretty slick, provided that I remember to compile my code in release mode before publishing it!

I wish I would’ve know about conditional compilation a while ago… it’s a really neat feature. It took me a while to get it working properly, and here is how.

  1. Start with a Visual Studio 2005 Web Application Project instead of the Visual Studio 2005 Web Site Project.  Note that you’ll have to download the Web Application Project because created after Visual Studio was released.  The application project behaves more like the Visual Studio 2003 web project and gives you “Build” options in the project’s Properties menu.
  2. Once you have the web project created, right-click on the project title and select Properties and then the Build tab.  You should see a screen like this.

  3. While Configuration is set to Debug, leave Define DEBUG constant and Define TRACE constant checked.  Then switch Configuration is set to Release and uncheck Define DEBUG constant and Define TRACE constant.

  4. The rest is easy.  In your code, you can use the conditional compilation directive #if to make sure the code you use to pre-populate your forms only exists in your code when Visual Studio .NET is in Debug mode:

    protected void Page_Load(object sender, EventArgs e) {

            if (!Page.IsPostBack) {

    #if DEBUG

                this.txtFirstName.Text = "John Doe";

    #endif

    }
    }

  5. Run your site in Debug mode and you should see your textbox named txtFirstName populated with “John Doe”.  Run it in Release mode and your form should be blank.  Sweet!

Obviously, to keep your code a bit cleaner, you should probably create a method that contains all your form population code and you can mark that method with a conditional attribute by marking it with [Conditional(“DEBUG”)].  Note that you will have to add the System.Diagnostics namespace to your file in order for this attribute to work.

So there you have it!  Make your UI testing a bit easier and still keep your production code clean.

Tuesday, July 25, 2006 11:16:11 PM UTC :: Filed Under Web Design

If you are a graphic designer, web designer, or any kind of artist or designer that gets paid for your designs, you must read Matthew Inman’s blog post, “How  to Ruin a Web Design.”  After you get done laughing, I would suggest printing the article and hanging it somewhere that your boss and co-workers can see it!

Wednesday, June 07, 2006 7:13:10 PM UTC :: Filed Under C# | Geek Tips | VB.NET

Ok, ok... it's not stealing because Microsoft said we can do it!   If you've ever wondered if you could use the icons in Visual Studio for other applications, apparently you can: Brad Abrams Blog: Standard Microsoft Icons

Wednesday, June 07, 2006 6:44:04 PM UTC :: Filed Under ASP.NET | C# | VB.NET | XML

One thing that was painfully lacking in Visual Studio 2003 was the ability to work with XML and XSLT.  Most people opted to purchase third party tools like XML Spy to deal with VS.NET's inadequacies.  However, Visual Studio .NET 2005 has a group of new tools that add things such as XSLT debugging and Intellisense that make working with XML related files much more tolerable.

In addition, the .NET Framework 2.0 has undergone some significant improvements in the System.XML namespace.  If you work with XML on a frequent basis, you'll want to be sure to read through these MSDN articles and see what's new in version 2:

Wednesday, May 24, 2006 4:14:21 AM UTC :: Filed Under Photography

I’ve been having problems with a SanDisk Ultra II compact flash card and thought I lost a handful of images that I took over the weekend.  Thanks to some help from the DPReview forums, I was pointed to the ArtPlus Digital Photo Recovery application.  It’s a nifty little free application that can recover photos from a corrupt memory card and did a pretty good job for me, even after I had reformatted my compact flash card!

Tuesday, May 23, 2006 1:38:28 PM UTC :: Filed Under SQL

How cool is this?  Red-Gate Software has a free plug-in for Query Analyzer that gives you Intellisense® support!  Click here to get it.

Navigation
On this page....
Search
Archives
<September 2006>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor