CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo [MVP]

Software management consultant and CTO, Headspring Systems

July 2005 - Posts

  • How to continue using NAnt with ASP.NET 2.0 - level 300

    First, if you aren't using NAnt for team builds in ASP.NET 1.1, shame on you.  Do that first.  When converting to Whidbey, you'll notice that your website no longer compiles to a single assembly and that multiple assemblies are created at JIT time.  This poses a small problem to the way we are used to scripting web application builds.

    You DO NOT want to copy everything in  your website to your production server.  There is no need for your code files to be out there.  Instead, you will want your NAnt script to build the whole website and deploy the binaries.  The solution task won't work for  you with a VS 8 solution.  You'll need to use an <exec /> target and kick of aspnet_compiler to precompile your web app to a stage folder and them use a <copy /> target to kick the files out to your server. 

    MsBuild does provide an AspNetCompiler task to do this, but it just kicks off aspnet_compiler.  MsBuild is still just a subset of NAnt, so I think it'll be a while before it can compete effectively (unless we find some proprietary stuff that we _really_ need).

  • XHtml DocType or DTD - level 200

    Especially as we move to ASP.NET 2.0, it's important to use an XHtml DocType or DTD.  ASP.NET 2.0 server controls will render valid XHtml transitional markup, so that's the most compelling Doctype, and that's the one I prefer, but pick one of the following:

    • XHtml 1.0 Transitional
      • <!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    • XHtml 1.0 Frameset (if you need to use <iframe />
      • <!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    • XHtml 1.0 Strict
      • <!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    The DocType needs to be the first line in the page; however, since XHtml is valid Xml, you can optionally add an Xml declaration at the top:

    <?xml version="1.0"?>

    And if you do this, the Xml declaration has to first, and then the DocType would come directly after.

  • How to ensure your web sites are valid Html (or XHtml) - level 300

    I originally was going to label this post level 200, but given how few people know about Html standards, I've labeled it 300, but I don't think this _should_ be an advanced topic.

    The first easy step is to try to validate your site with a validator.  The one I use is from the W3C: http://validator.w3.org/.  Type in the site, and it will tell you what is wrong with it.  A series of events brought my focus back to this.  I've posted on this topics previously here, here, here, here, and here

    I was setting some CSS overrides for my Community Server blog, and I wasn't getting the results I wanted.  Then I inspected the page to find that the default skin of Community Server doesn't set a DocType.  I was very surprised by this since Telligent has been on the ball on so many things.  Telligent's own web site uses the XHtml 1.1 DocType, but it doesn't validate.

    Not including a DocType at all leaves the browser guessing as to what kind of markup your page is.  IE will assume Html 3.2 or (quirks mode).  FireFox wants to render it as Html 4.01 transitional.  In fact, if you use the default DocType in VS.Net 2003, you'll be using an incomplete one that omits the location of the .dtd document.  You can write valid Html 4.0 this way (and I commend Microsoft for having a main page that correctly validates), but IE will still operate in quirks mode.  This may cause you some grief when laying out your pages because you will have unpredictable browser behavior.

    Adhering to web standards greatly simplifies web application development when you need an attractive user interface.  There are some simple steps that even a beginning programmer can employ to ensure the web application is valid markup:

    • Add a DocType to the top of every page (or your master page in ASP.NET).  I recommend using:
      <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    • Validate your app with the W3C validator.
    • Fix every error it finds.

    These simple steps can lead anyone to standards-compliant web application.

  • Living in the most unwired city in the world (ok, Texas) - level 000

    Intel has name Austin, TX the 3rd most unwired city in the U.S.  Whenever I am out and about and have a few hours to kill, I pop open my laptop and do some .Net work.  I always have projects going.  A new project that's about to start up is a distributed open-source project for the Austin .Net User Group at Adnug.org.   I have a Subversion repository for source code, and we'll accept code patches from anyone who wants to submit them.  We haven't defined the project yet, so we'll see how it goes.  I have no problem finding a location that offers free wireless internet.  Many businesses have added it to their signs, so it's easy to spot.  And Schlotzky's is the old stand-by with free wifi at every location.

    Some different surveys have slightly different results.  Here are some:

    Being a developer, I'm glad that it's easy to get connected.  I take my laptop with me wherever I go now.  I can take advantage of development time even when I'm waiting my Firestone to change the oil in my truck, and when I just can't find the Wifi, I use the FutureDial USB cable for my Sprint phone to get on the Net through my mobile phone.

  • Objections to Agile development - level 300

    Whether you love or hate Agile development methodologies, you need to read a whitepaper by Jim Highsmith entitled "Objections to Agile Development". 

    Jim addresses objections that stakeholders make to Agile development.  The categories are:

    • Buyer reality
    • Bad or no design
    • Doesn't work with our business partners
    • No documentation

    For each of the objections above, Jim does a fine job of explaining why these objections are unfounded.  I'll address the "no documentation" bullet from my own experience, but please read the whitepaper as well.  I've battled many objections to Agile at a previous job.

    If you've ever created design documentation (UML diagram, etc), you know that it is out of date as soon as it's printed.  Developers make design decisions throughout the coding process (Coding is design, and Jack Reeves take).  It takes a lot of time to keep a design document current, and it just never happens.  Design documents get created; they are shown to management; they look pretty, and they are plain wrong.  They never describe the actual structure of the system.  A manager may like them, but they are looking at a picture, not the actual system.  The actual system ends up structured in a different way, but the manager doesn't know.  The manager isn't reading the code.  The manager goes on in ignorant bliss with a picture of something that doesn't exist.  Arguements can be made about how the process is "supposed" to work, but there's also reality.

    The time for documentation is when the project is finished, and it's time for it to be mothballed.  This is when documentation should be created for maintainers who may come later.  The system has stopped changing and is actually in a state where it can be documented.  This is maintenance documentation.

    Throughout the project, the code and tests should be the documentation for the code.  This is the only thing that is guaranteed to remain current.  Developers should be able to look at the structure of the system in the IDE and understand it.  The whole solution layout also has documentation qualities.

    I'd be interested in finding out if anyone has created a design document before the system was created where the document actually stayed current and meaningful.

  • How to develop an ASP.NET web project without IIS binding - level 200

    If you've every shared an ASP.NET project or worked on one on multiple computer, you know what a pain it is to ensure that all computers have the same IIS virtual directory configured.  If you don't, the project won't open.

    For ASP.NET 1.1, it's easier to use a class library project instead of a web project.  You lose a bit of designer support, but you gain project portability.  If you are like me, you don't use the designer at all, and it's all gain and no loss.

    The trick is to delete the *.csproj.webinfo file,  take your web project and open the .csproj file in notepad.  Then find the following at the top of the file:

    <VisualStudioProject>
        <CSHARP
            ProjectType = "Web"
            ProductVersion = "7.10.3077"
            SchemaVersion = "2.0"
            ProjectGuid = "{09E1A7E2-B51D-42EA-A2BE-4A5991BDF2A7}"
        >. . . . . . .

    And just change "Web" to "Local"

    <VisualStudioProject>
        <CSHARP
            ProjectType = "Local"
            ProductVersion = "7.10.3077"
            SchemaVersion = "2.0"
            ProjectGuid = "{09E1A7E2-B51D-42EA-A2BE-4A5991BDF2A7}"
        >. . . . . <snip/>

    Literally, that's all it takes.  Now your poject opens as a class library, and you just set up IIS to wherever the project is.  You can debug just like before, and you can use pages and user controls just like before.

    One note:  Change the project type back to "Web" before upgrading to .Net 2.0 or the project conversion wizard won't properly create a website.

     

  • How to host your source code for distributed projects - level 000

    Fabrice posted a great list of source control hosters.  I'm definitely going to give them a try.
  • Steven Smith as RD - level 000

    Congrats to Steven Smith, who has recently become a Microsoft Regional Director.  Steve is the second (that I know about) .Net community leader to have been deployed to Iraq.  He was deployed shortly after I returned from being in Iraq for a year.  I was able to give him some tips, and I had the opportunity to meet him in person at Tech Ed.

    For those who don't know, a MS Regional Director is a volunteer who assists the MS developer community in a specific area.  If you have a question or issue, call them up.  Shoot them an email.  They are there to help.  If you live in Texas, there are several:  Go to this page, http://www.microsoftregionaldirectors.com/Public/rdFindNC.aspx, and search for US - Texas.  I'm disappointed that the website is designed so poorly.  You can only get to information through form posts, so I was unable to get a link directly to a filtered list.

  • AgileATX lunch meeting tomorrow (Austin, TX) - level 000

    Food and agile development talk at the Central Market Cafe at Lamar
    and 38th (http://tinyurl.com/brxsz). Upstairs in the gallery.

    Tursday, July 21st, 11:30 AM

    This is a group local to Austin, TX, and while we happen to be more .Net focused, we're more concerned with common-sense development, and that leads us to Agile.  This group is made up of many members of the Austin .Net User Group as well as some Java folks who are interested in Agile development methodologies and design.  I'd also like to Welcome Jeremy Miller, an AgileATX practitioner who has recently joined CodeBetter.

    Check out the Yahoo group at

    http://groups.yahoo.com/group/AgileATX/

  • How to tag with Shadows.com - ASP.NET showcase

    As I mentioned before, I'm at a new company, and I'm one of the .Net developers working on Shadows.com.  This is all ASP.NET with C#, and we're doing a lot of cool things inside the site.  Shadows.com is centered around community tagging, rating, and commenting.  It then faciliates searching on the community's tags.  With the commenting feature, any page on the Net could be the start of a discussion thread.  Tagging allows similar sites to be grouped together. 

    If you look at my blog: http://www.jeffreypalermo.com, you'll see that I've added an image link on the left and a text link on the right.  The image link will take you to my profile page on Shadows.com, and the text link on the right will take you to a shadow page for the current post you are reading.  Every page on the Internet can have a "shadow" page, which is a page about that page.  The shadow page contains tags, ratings, and comments about the source page, so the shadow page is an extension of my blog post, or any other page.

    Most developers don't get the chance to work on an application that gets very high usage, like those on the public Internet, so I feel fortunate that I have this experience.

    I'll surely be posting any ASP.NET lessons learned throughout the life of this project.  I've already posted some:

    Be sure to download the toolbar for IE or Firefox.  It'll allow you to tag sites on the fly.

  • How to make an ASP.NET user control behave like a custom WebControl - level 200

    If you've used User Controls for any amount of time, you've lamented that there is no containing control for attributes.  With any other custom controls, you have WebControl as the base class, and that allows you to use a <span/> by default or change the TagKey to another tag, and when you declaratively set an attribute like [style="padding:10px;"], the attribute automatically gets added to the tag.

    Not so with User Controls, but they aren't designed to work that way.  They are meant to be pagelets: a portion of a page.  A User Control can contain anything and doesn't have to be encapsulated in any control, so there is no tag to add attributes to.

    I have made a hybrid User-Custom web control.  It inherits from UserControl, so I have the nice declarative layout, but I needed functionality of a WebControl as well.  I added a WebControl as a member of my user control, and on PreRender, I wrap all my user control contents in this WebControl.  Then I bestow all the attributes of the user control on the WebControl and add the WebControl as the only 1st-level child of the user control.  The end result is that I have a user control that wraps itself in a <span/> or whatever tag I want, and I can set attributes on the Page, and they will get rendered to the browser.  This is especially useful when I need to add a style property or "class".

    Here's my code-behind.  Feel free to copy/steal my code:

       14     public class Magic : System.Web.UI.UserControl

       15     {

       16         private WebControl _frame;

       17 

       18         public WebControl Frame

       19         {

       20             get {

       21                 this.EnsureChildControls();

       22                 return this._frame;

       23             }

       24         }

       25 

       26         protected override void CreateChildControls()

       27         {

       28             base.CreateChildControls ();

       29 

       30             this._frame = new WebControl(HtmlTextWriterTag.Div);

       31         }

       32 

       33         protected override void OnPreRender(EventArgs e)

       34         {

       35             base.OnPreRender (e);

       36 

       37             Control[] ctrls = new Control[this.Controls.Count];

       38             this.Controls.CopyTo(ctrls, 0);

       39 

       40             foreach(Control ctrl in ctrls)

       41             {

       42                 this.Frame.Controls.Add(ctrl);

       43             }

       44 

       45             foreach(string attribute in this.Attributes.Keys)

       46             {

       47                 this.Frame.Attributes[attribute] = this.Attributes[attribute];

       48             }

       49 

       50             this.Controls.Add(this.Frame);

       51         }

       52 

       53 

       54         private void Page_Load(object sender, System.EventArgs e)

       55         {

       56             // Put user code to initialize the page here

       57         }

       58 

       59         #region Web Form Designer generated code

       60         override protected void OnInit(EventArgs e)

       61         {

       62             //

       63             // CODEGEN: This call is required by the ASP.NET Web Form Designer.

       64             //

       65             InitializeComponent();

       66             base.OnInit(e);

       67         }

       68 

       69         /// <summary>

       70         ///        Required method for Designer support - do not modify

       71         ///        the contents of this method with the code editor.

       72         /// </summary>

       73         private void InitializeComponent()

       74         {

       75             this.Load += new System.EventHandler(this.Page_Load);

       76         }

       77         #endregion

       78     }

    Here is my user control markup:

    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="Magic.ascx.cs" Inherits="MagicUserControl.Magic" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    This is a tag.
    <asp:Label Runat="server">Yo, buddy</asp:Label>

    And here is my Page markup (where my User Control is used):

    <uc1:Magic id="Magic1" style="margin: 10px;" myAttrib="Palermo" Frame-CssClass="myClass" runat="server"></uc1:Magic>

    See how easy it is now to add any sort of attribute and have it render?  I created this control out of necessity because I wanted the simplicity of user controls with the power and flexibility of a WebControl-derived control.

  • New Microsoft Certifications (~Dec 2005) - level 000

    For a while now, Microsoft has had:

    • Microsoft Certified Systems Engineer (MCSE) - wow, Engineer!
    • Microsoft Certified Solutions Developer (MCSD)
    • and the new Microsoft Certified Application Developer (MCAD)

    There are plenty of people with the MCSD that went along with the VB track, and now you pretty much have to use MCSD for .Net to be clear if you have the new certification.  You've probably met someone with one of these certifications that was a blabbering idiot, and the cert has lost credibility in your mind. 

    I have the MCSD for .Net certification, and I can say from experience that earning the cert was similar to earning a college degree.  As long as you stuck it out, you'd get it.  After all, how many blabbering idiots do you know with a college degree?  If we can't keep idiots from getting degrees, then how can we possibly expect Microsoft to solve the same problem with their certifications?

    Even so, Microsoft is _attempting_ to improve the certification program, and will be introducing some new choices for developers.  For right now, the title is planned to be "Microsoft Certified Professional Developer".  MCPD.  For us MCSDs, two exams will be required to upgrade the certification.  According to the article at MCP Mag, MCPD requires the person to first earn MCSD.  It seems to me that the new certifications are aimed toward correctly identifying those that can deploy a specific Microsoft technology.

    You can do the MCAD now and get certified in either Windows or Web (pick your language), but there is no distinction for those who might be super integration developers:  those writing web services and windows services and class libraries that integrate other systems.  That is just as important, but for now, Microsoft only has the UI tracks. 

    Another hole is design.  All the certifications (current and planned) identify those who can use a Microsoft tool or runtime, but they do nothing to ensure that the person understands anything about software design.  Where are the OO questions?  What about other things in software like cyclomatic complexity?  Besides just using .Net to crank out an application, what about the things that differentiate mediocre developers from great ones?  What about security?  These questions go past Microsoft certifications, however, and they apply to every software developer in the industry, not just .Net devs. 

    I think industry certifications will come as the software industry matures (but I think back to how many years railroad venders made tracks of different widths).

    I expect the certification plans to change a bit before December, but whatever they come out with, I'll bite:  have to keep that resume current!

  • Martin Fowler - get well soon!

    Everyone in our industry know who Martin Fowler is, and we've all read his published works.  I learned so much from his book, Refactoring.  He had a cycling accident recently and is recovering in the hospital.  Martin, get well soon.
  • Visual Studio Team System presentation at the Austin .Net UG meeting tonight - level 000

    Tonight, Chris Menegay will be presenting on Visual Studio Team System.  As usual, a healthy supper of pizza and soda will be provided at the Austin Microsoft Technology Center.  Go to www.adnug.org for more details.  In case you might be new to the group, I'm one of the officers as well as the South TX INETA liaison.  More details below:

     Topic:  Implementing Process - Visual Studio 2005 Team System Overview
    Software projects fail for a variety of reasons. Most of the difficulties are not due to technology, but due to lack of visibility and predictability. Microsoft's forthcoming Visual Studio 2005 Team System will improve on these challenges as well as impact how applications are designed, developed, tested, and deployed. Visual Studio 2005 Team System will offer advanced application lifecycle management tools and processes that will assist organizations in delivering their solutions on time and under budget. In this session, you will get a glimpse of these new tools and gain an insight into Microsoft's approach to this market.

    SpeakerChris Menegay
    Software projects fail for a variety of reasons. Most of the difficulties are not due to technology, but due to lack of visibility and predictability. Microsoft's forthcoming Visual Studio 2005 Team System will improve on these challenges as well as impact how applications are designed, developed, tested, and deployed. Visual Studio 2005 Team System will offer advanced application lifecycle management tools and processes that will assist organizations in delivering their solutions on time and under budget. In this session, you will get a glimpse of these new tools and gain an insight into Microsoft's approach to this market.

    Date/Time7/11/2005 5:30:00 PM - 7/11/2005 7:30:00 PM

    Location
    Microsoft Technology Center
    Stonebridge Plaza, Building One, 9606 N. Mopac, Ste. 200, Austin, TX 78759
    512-795-5300

  • How to decide: user controls vs. composite controls vs. rendered custom controls

    There are several ways to make your own server controls in ASP.NET.  You may have wondered which type you should make.  There are two basic types:
    • user controls
    • custom controls
    Within custom controls, you have rendered controls, and composite controls.  A composite control could merely inherit from another control and change or add something.  More often, though, it creates many child controls to render inside itself.

    A User Control is the easiest to make, and it was originally going to be called "pagelets" because the creation experience is pretty close to that of a page.  You have the html view and a code-behind.  It's just a snippet of what would go on a page.  You can lay out your html and add other server controls inside, and then control them with your code-behind.  This type of control should be considered first.  If you need a control that is specific to a particular application, this type of control is for you.

    A custom control is all code and is compiled into an assembly.  The main benefit is that the assembly can be distributed and shared among many applications.  If you don't need to share controls between applications, then it may be hard to justify using this type of control.  This control is more time-consuming to create.  One valid reason may be that you need a control all over in your application.

    Within the custom control umbrella, you have the rendered controls and composite or inherited controls.  I prefer the inherited controls myself.  Often, I'll inherit from a Panel (a <div/>) and add other controls as children.  Another method some prefer is rendered controls.  This is when you inherit from Control and override the Render method and output all html yourself.  This can quickly become cumbersome and if very error-prone.  I would consider this a last resort.  In some cases, a performance argument is made, and your decision will have to be based on the application environment.

    In summary, if you need to distrubute controls in an assembly, you will have to use custom controls and decide between rendered or composite.  If all your controls will stay with the application, user controls are the most compelling answer.

    A must read for every ASP.NET developer is Developing ASP.NET Server Controls and Components.

    In the current events space, contratulations to .Net Junkies for upgrading their blogging engine to Community Server.

    Update:  Thank you Fregas for the correction.  I'm very excited about declaratively setting properties on user controls.
More Posts Next page »

This Blog

Syndication