codebeater

General .NET, ASP.NET, C# and VB.NET discussion

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

ASP.NET MVC Preview 3 Release

Scott Guthrie announced today that they've released the Preview 3 build of the ASP.NET MVC framework.  This new build includes features not included in last month's build including Visual Studio tool integration and documentation plus some enhancements/refinements.

Read the entire article

Download an integrated ASP.NET MVC Preview setup package here.

Download the ASP.NET MVC Preview 3 framework source code and framework unit tests here.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,
Categories: .net | asp.net | MVC
Posted by Jeff on Tuesday, May 27, 2008 3:36 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Concerned about SEO? Think twice before using that LinkButton control

Most people concerned about SEO (Search Engine Optimization) know that search engines use the links on your pages to travel the depths of your site for content.  So how does a LinkButton fit into this strategy?  Take a look:

<asp:LinkButton ID="lbtnAbout" runat="server" PostBackUrl="~/About.aspx">About</asp:LinkButton> 

This tag renders like this:

<a id="lbtnAbout" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;lbtnAbout&quot;, &quot;&quot;, false, &quot;&quot;, &quot;About.aspx&quot;, false, true))">About</a> 

Notice that the link is actually a JavaScript call.  At most, the search engine will extract the title of the hyperlink and include it as part of the body, but it won't touch the javascript.  What does this mean?  It means that the link is essentially invisible to search engines.  When thinking in terms of SEO this is BAD.

I won't argue that there won't ever be uses for LinkButtons (like when you need to execute server-side code on the postback), but if you're optimizing for SEO then it may make sense to just use a regular hyperlink, when possible.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,
Categories: asp.net
Posted by jeff on Friday, May 23, 2008 7:55 PM
Permalink | Comments (0) | Post RSSRSS comment feed

CSS Message Boxes for different message types

"Janko at Warp Speed" has a great article that demonstrates how to create an ASP.NET user control that supports different message types and how to style them using CSS.  It also explains how to style ValidationSummary similarly.  It's a very nice CSS example.

Read the entire post 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Jeff on Thursday, May 22, 2008 9:07 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Enterprise Library 4.0 for Visual Studio 2008 - Released!

Somehow I missed this announcement a few days back, but here it is anyway:

The sixth release of the enterprise library has been released and it includes all the blocks you're already familiar with updated for Visual Studio 2008, plus the new Unity Application Block for dependency injection.

What’s New in v4.0?

This release of Enterprise Library includes the following:

  • Integration with the Unity Application Block
  • Windows Management Instrumentation (WMI) 2.0 support and improved instrumentation
  • Performance improvements (particularly, in the Logging Application Block)
  • Pluggable Cache Managers
  • Visual Studio 2008 support
  • Bug fixes

Note: existing public APIs (v3.1) are still supported.

The Application Block Software Factory and the Strong Naming Guidance Package are not included in this release but are available as a separate download. Thus, there is no longer a dependency on Guidance Automation Extensions (GAX).

 Read the entire article at Tom Hollander's blog:  http://blogs.msdn.com/tomholl/archive/2008/05/17/enterprise-library-4-0-get-it-while-it-s-hot.aspx

Quick Links:

– MSDN site: http://msdn.microsoft.com/entlib

– Community Forum: http://go.microsoft.com/fwlink/?LinkID=119312

– Community Extensions: http://codeplex.com/entlibcontrib

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Jeff on Wednesday, May 21, 2008 1:44 PM
Permalink | Comments (0) | Post RSSRSS comment feed

SEO & ASP.NET: Put keywords in the URL

In what areas does Google look for keywords?  There are 3 documented areas; URL, Title, and the body of your content.  How does Google find the keywords in URLs?  Does the order of the keywords matter?  Rob Howard answers these questions and more in his post SEO & ASP.NET: Put keywords in the URL.  If you're at all interested in SEO I recommend taking a look.  I haven't read the entire series yet but it appears to be extremely informative and an easy read.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,
Categories: .net | asp.net | SEO
Posted by Jeff on Tuesday, May 20, 2008 5:38 PM
Permalink | Comments (0) | Post RSSRSS comment feed

ASP.NET AJAX Control Toolkit TabContainer Theme Gallery

I've recently discovered Matt Berseth's blog and can say, quite honestly, that it is full of excellent posts including this one which shows a bunch of very cool themes with which you can style the TabContainer control in the ASP.NET AJAX Control Toolkit.  Be sure to check out the live gallery while you're there too.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,
Categories: .net | asp.net | ajax
Posted by Jeff on Tuesday, May 20, 2008 12:03 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Generating markup to display a scaled image

I'm working on an application where I have the need to display properly scaled images within an area of limited size.  I considered two different approaches for this problem.  First, I can use the framework's image class to resize the image on disk when the user initially downloads it, but since I also need to display at a larger size I would need to keep two copies.  The primary benefit to this approach, as I see it, is that it would reduce the size of the image on disk, therefore reducing the amount of data downloaded by the user.  The second approach, and the one I'll demonstrate here, involves simply setting the size attributes of an img tag to display the properly scaled image within the specified area.

    /// <summary>
    /// Creates the markup to display an image scaled to a specified size.
    /// </summary>
    /// <param name="maxWidth">A <see cref="T:System.Int"></see> indicating the maximum available width.</param>
    /// <param name="maxHeight">A <see cref="T:System.Int"></see> indicating the maximum available height.</param>
    /// <param name="relativeImagePath">The relative path to the image.</param>
    /// <returns></returns>
    public static string GetThumbnailMarkup(int maxWidth, int maxHeight, string relativeImagePath)
    {
        if (string.IsNullOrEmpty(relativeImagePath))
            throw new ArgumentNullException("relativeImagePath");

        System.Drawing.Image currentImg = null;
        string fullPath = HttpContext.Current.Server.MapPath(relativeImagePath);

        using (currentImg = System.Drawing.Image.FromFile(fullPath))
        {
            int sourceWidth = currentImg.Width;
            int sourceHeight = currentImg.Height;
            float percent;
            float heightPercentage;
            float widthPercentage;

            widthPercentage = ((float)maxWidth / (float)sourceWidth);
            heightPercentage = ((float)maxHeight / (float)sourceHeight);
            if (heightPercentage < widthPercentage)
            {
                percent = heightPercentage;
            }
            else
            {
                percent = widthPercentage;
            }

            int scaledWidth = (int)(sourceWidth * percent);
            int scaledHeight = (int)(sourceHeight * percent);

            return @"<img src=""" + relativeImagePath + @""" height=""" + scaledHeight.ToString() + @""" width=""" + scaledWidth.ToString() + @""">";
        }
        
        return string.Empty;
    }

I'm sure there are better ways to do this, so if you know of one please feel free to share.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Posted by jeff on Wednesday, May 14, 2008 4:45 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta - Nuggets of goodness

I noticed on Scott Guthrie's blog that the Visual Studio 2008 and .NET 3.5 Service Pack Beta have been released into the wild.  This beta brings about a whole slew of bug fixes and throws in some performance improvements for good measure. 

The beta can be downloaded from here.

Before I talk about the features in this service pack I wanted to raise a little awareness about a potential issue with the install.  I noticed in the comments to Scott's post a few issues with installations.  Apparently, if you you have previously installed some other beta stuff, such as Silverlight Tools for Visual Studio, you want to be sure to uninstall that stuff before installing the service pack.  I've also read that the install is a long one.

This service pack is not just bug fixes, it contains several new items of note.  I'm just going to summarize since you can read the details on Scott Guthrie's blog.

First, in web development:

  • ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)
  • ASP.NET Routing Engine (System.Web.Routing)
  • ASP.NET AJAX Back/Forward Button History Support
  • ASP.NET AJAX Script Combining Support
  • Visual Studio 2008 Performance Improvements in the HTML Designer and HTML Source Editor
  • Visual Studio 2008 JavaScript Script Formatting and Code Preferences
  • Better Visual Studio JavaScript Intellisense for Multiple JavaScript/AJAX Frameworks
  • Visual Studio Refactoring Support for WCF Services in ASP.NET Projects
  • Visual Studio Support for Classic ASP Intellisense and Debugging
  • Visual Web Developer Express Edition support for Class Library and Web Application Projects

Client Development:

  • Application Startup and Working Set Performance Improvements
  • New .NET Framework Client Profile Setup Package
  • New .NET Framework Setup Bootstrapper for Client Applications
  • ClickOnce Client Application Deployment Improvements
  • New Windows Forms Controls (vector shapes, printing, and DataRepeater controls)
  • WPF Performance Improvements
  • WPF Data Improvements
  • WPF Extensible Shader Effects
  • WPF Interoperability with Direct3D
  • Several VS 2008 for WPF Improvements

Data Development

  • SQL 2008 Support
  • ADO.NET Entity Framework and LINQ to Entities
  • ADO.NET Data Services (formerly code-named "Astoria")
  • WCF Development Improvements

There are also a few VB, C# and Team Foundation Server improvements.  Overall it appears to be a fairly comprehensive service pack with loads of goodies.  I haven't really messed with Silverlight yet and don't plan to until 2.0 is released, so for this service pack I'm particularly interested in the new ASP.NET Routing Engine and the ASP.NET Script Combining support.  Of course, all performance improvements are always welcome, too.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Posted by jeff on Monday, May 12, 2008 2:35 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Automatic Properties and Object Initializers

Ok, this is not new news but, after talking with a few of my colleagues, I recently realized there are still people who don't know about it. So here's a brief explanation... Properties in C# usually consist of a private member variable and a property to read/set values from/to that variable. They look something like this:

public class DocumentInfo
    {
        private string _path;
        private Int32 _docId;

        public string Path
        {
            get
            {
                return _path;
            } 
            set
            {
                _path = value;
            }
        }

        public Int32 DocumentId
        {
            get
            {
                return _docId;
            } 
            set
            {
                _docId = value;
            }
        }
    }

 

Now, in cases like this where there is no get/set logic inside the properties you can easily reduce the amount of code by using automatic properties and letting the compiler fill in the blanks.  Automatic properties basically allow you to bypass coding the get/set sections as well as the private member variable, like this:

 

public class DocumentInfo
    {
        public string Path { get; set; }
        public Int32 DocumentId { get; set; }

    }

 

This, as you can see, significantly reduces the amount of code you have to write.  Of course, if you need get or set validation or other logic this approach will not work for you.  Also, why not just use public fields instead of properties?  One reason would be that once you expose items as fields and other objects consume those fields you would be unable to change them to properties later, should you need to add validation logic, without having to also recompile the consumers.

Notice in the above example that I did not provide a constructor.  This is something I would typically avoid in my own code but, often, when dealing with third party assemblies you may be faced with objects like this.  To properly initialize the object you may set the properties after it has been created, like this:

 

public void foo()
{
    DocumentInfo di = new DocumentInfo();
    di.Path = "c:\\some folder\\somefile.txt";
    di.DocumentId = 1;
}

 

A new feature in the framework, called object initializers, makes this initialization a bit more concise:

 

public void foo()
{
    DocumentInfo di = new DocumentInfo(Path="c:\\some folder\\somefile.txt", DocumentId=1);
}

This, in my opinion, is clearly more concise than the previous example and provides a contructor-like syntax for dealing with third party tools that have, for whatever reason, not provided constructors for their objects.

For more information on automatic (auto-implemented) properties visit Auto-Implemented Properties (C# Programming Guide).

For more information on object intializers visit Object and Collection Initializers (C# Programming Guide).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Posted by jeff on Monday, May 12, 2008 11:15 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Lessons learned; debug="true"

Not too long ago I was working on a web app at my place of employment with several other people. It's a fairly complex app that makes heavy use (too much, IMO, but that's a different story) of AJAX. When we finally made this application available for beta testing our IT department was quick to point out that each request was causing over 1MB of bandwidth usage. After my initial shock my first impression was that the problem was being caused by the set of 3rd party tools we were using. However, a simple test using a page with intrinsic framework controls revealed that my suspicions were incorrect. It took many hours of frustration but eventually I noticed that debug in web.config was set to 'true'. Once I set it to false our bandwidth usage dropped to a very reasonable amount in the range of 12k to 75k, depending on the data being served. So, use my experience as a lesson and don't ever forget to set debug="false" before deploying.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Jeff on Monday, May 05, 2008 1:38 PM
Permalink | Comments (1) | Post RSSRSS comment feed