<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Kevin Isom</title><subtitle type="html">Just a good ol' boy, by-God Virginia-proud and country-sophisticated -- sort of like a John Deere tractor with air conditioning and satellite radio.</subtitle><id>http://weblogs.asp.net/kevinisom/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/kevinisom/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2007-10-12T09:58:22Z</updated><entry><title>Generating Images With .Net Part 1</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2009/12/11/generating-images-with-net-part-1.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2009/12/11/generating-images-with-net-part-1.aspx</id><published>2009-12-11T04:11:00Z</published><updated>2009-12-11T04:11:00Z</updated><content type="html">&lt;p&gt;I’ve recently had a project that required a great deal of image generation and manipulation. Not having done image manipulation in a good long while I thought it would be good to capture some of the “tricks of the trade”. One of the things I noticed in my searching for information on generating images in .Net is how bad variables were named. Hungarian notation or single letter names. This is not cool so I’m going to be trying to use descriptive names for all of my variables. &lt;/p&gt;  &lt;p&gt;In this post I’ll cover how to display an image via the HttpResponse and then to generate an image from text.&lt;/p&gt;  &lt;h2&gt;Displaying Any Image&lt;/h2&gt;  &lt;p&gt;The following Code will write out the image to the HttpResponse in order for it to be displayed.&lt;/p&gt;  &lt;div&gt;   &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; WriteImageToResponse(HttpContext context, Image imageToServe)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     context.Response.ContentType = &lt;span style="color: #006080"&gt;&amp;quot;image/png&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (MemoryStream memStream = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MemoryStream())&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;         imageToServe.Save(memStream, ImageFormat.Png);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         imageToServe.Dispose();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         memStream.WriteTo(context.Response.OutputStream);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         memStream.Dispose();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;So the method takes the &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx"&gt;image&lt;/a&gt; and the &lt;a title="HttpContext at MSDN" href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx"&gt;HttpContext&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;It sets the response type to image/png, you could also set the response type to other &lt;a title="different response content types" href="http://www.iana.org/assignments/media-types/image/"&gt;types of images&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;Next I new up a memory stream and then save the image into the memory stream with the &lt;a title="ImageFormat class on MSDN" href="http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat.aspx"&gt;ImageFormat&lt;/a&gt; set to &lt;a title="Members of the ImageFormat" href="http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat_members.aspx"&gt;Png&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Then I call dispose on the image class to make sure it doesn’t hang around eating up resources.&lt;/li&gt;

  &lt;li&gt;Next the &lt;a title="The WriteTo method on MSDN" href="http://msdn.microsoft.com/en-us/library/system.io.memorystream.writeto.aspx"&gt;WriteTo&lt;/a&gt; method of the memory stream &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Generating a Text Image&lt;/h2&gt;

&lt;p&gt;The following code sample will show how to generate an image from a text with an outline.&lt;/p&gt;

&lt;h3&gt;Setting the stage&lt;/h3&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; var fontCollection = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PrivateFontCollection();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; var fontSize = 72.0f;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; var fontLocation = &lt;span style="color: #006080"&gt;&amp;quot;fonts/BIRDMAN_.ttf&amp;quot;&lt;/span&gt;; &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; fontCollection.AddFontFile(context.Server.MapPath(fontLocation));&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; SolidBrush colorBrushForText = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidBrush(ColorTranslator.FromHtml(&lt;span style="color: #006080"&gt;&amp;quot;#567DB6&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; StringFormat formatOfText = StringFormat.GenericTypographic;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; textToDraw = &lt;span style="color: #006080"&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; var startingPointForText = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PointF(44, 20);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt; var imageToRender = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Bitmap(600, 500);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;The code is setting up the Font from a location on the website (this is useful as you don’t need to install the font on the server) &lt;/li&gt;

  &lt;li&gt;Also the size of the font, as well as the color to be used for the text.&lt;/li&gt;

  &lt;li&gt;Next I specify the format of the text and set the text that will be generated&lt;/li&gt;

  &lt;li&gt;Then I specify the starting point of the text&lt;/li&gt;

  &lt;li&gt;Finally I create a new &lt;a title="Bitmap class on MSDN" href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx"&gt;Bitmap&lt;/a&gt; with a width and height&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Drawing The Text&lt;/h3&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (var masterGraphic = Graphics.FromImage(imageToRender))&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     masterGraphic.Clear(Color.White);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     masterGraphic.SmoothingMode = SmoothingMode.AntiAlias;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//uncomment the following line if you just want the text drawn&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//masterGraphic.DrawString(textToDraw, fontToDraw, colorBrushForText, new PointF(xCoordinate, startingPointForText.Y), formatOfText);&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     GraphicsPath pathOfText = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; GraphicsPath();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     pathOfText.AddString(textToDraw, fontCollection.Families[0], (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)FontStyle.Regular, fontSize, startingPointForText, formatOfText);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     Pen outlinePen = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Pen(Color.Black, 2);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     masterGraphic.DrawPath(outlinePen, pathOfText);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     SolidBrush solidBrushForText = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidBrush(ColorTranslator.FromHtml(&lt;span style="color: #006080"&gt;&amp;quot;#567DB6&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     masterGraphic.FillPath(solidBrushForText, pathOfText);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     DisposeObjects(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;IDisposable&amp;gt;{pathOfText,formatOfText,colorBrushForText, solidBrushForText,outlinePen});&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     masterGraphic.Save();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; WriteImageToResponse(context, imageToRender);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The code starts by taking the bitmap created earlier to be used as the “canvas” for the drawing &lt;/li&gt;

  &lt;li&gt;The method call to Clear setting the background to white&lt;/li&gt;

  &lt;li&gt;Next the &lt;a title="The SmoothingMode enumeration on MSDN" href="http://msdn.microsoft.com/en-us/library/z714w2y9.aspx"&gt;SmoothingMode&lt;/a&gt; is set to &lt;a title="Anti-Alias description at wikipedia" href="http://en.wikipedia.org/wiki/Anti-alias"&gt;AntiAlias&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;A &lt;a title="GraphicsPath at MSDN" href="http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx"&gt;GraphicsPath&lt;/a&gt; is instantiated, this is the path of the text to be drawn.&lt;/li&gt;

  &lt;li&gt;Now the Pen object is created to hold the color that will be used to draw the outline of the text.&lt;/li&gt;

  &lt;li&gt;The method call to &lt;a title="DrawPath method on the Graphics Class at MSDN" href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawpath.aspx"&gt;DrawPath&lt;/a&gt; with the path of the text passed and the pen with the outline color set.&lt;/li&gt;

  &lt;li&gt;Now a new brush for the main text is created.&lt;/li&gt;

  &lt;li&gt;Then the path is filled with the main color.&lt;/li&gt;

  &lt;li&gt;The objects that implement &lt;a title="IDisposable interface at MSDN" href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx"&gt;IDisposable&lt;/a&gt; are passed to a method that disposes them.&lt;/li&gt;

  &lt;li&gt;The graphic object has it’s save method called that generates the image in the bitmap that was passed&lt;/li&gt;

  &lt;li&gt;Finally the graphic is written to the response.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The output&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/CropperCapture10_0AC8EE8D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CropperCapture[10]" border="0" alt="CropperCapture[10]" src="http://weblogs.asp.net/blogs/kevinisom/CropperCapture10_thumb_117E88C1.png" width="539" height="92" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I hope this helps someone, and I hope it’s clear cut. In upcoming posts I’ll be explaining how to combine images, crop images and drawing shapes among other things.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2009%2f12%2f11%2fgenerating-images-with-net-part-1.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2009%2f12%2f11%2fgenerating-images-with-net-part-1.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7276088" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Code" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Code/default.aspx" /><category term="graphics" scheme="http://weblogs.asp.net/kevinisom/archive/tags/graphics/default.aspx" /></entry><entry><title>REST as Simple as Possible</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2009/02/21/rest-as-simple-as-possible.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2009/02/21/rest-as-simple-as-possible.aspx</id><published>2009-02-21T08:07:00Z</published><updated>2009-02-21T08:07:00Z</updated><content type="html">&lt;P&gt;I've been doing a lot of &lt;A title="Representational State Transfer @ Wikipedia" href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target=_blank mce_href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/A&gt; based services lately and for something that is as simple a concept as &lt;A title="Representational State Transfer @ Wikipedia" href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target=_blank mce_href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/A&gt; it is actually not the easiest thing to find guidance for a .Net developer. It's simple, or at least it should be. My first stop was the WCF Rest Starter Kit. I thought great, surely this would get me going with no fuss. I only wish it were so. I thought I could create a project with it and just get going. Instead what I got was a whole heap of code that didn't really start me on the way at all. I won't totally bag on the starter kit. I rather like the items around the &lt;A href="http://www.atomenabled.org/developers/protocol/" target=_blank mce_href="http://www.atomenabled.org/developers/protocol/"&gt;atom publishing protocol&lt;/A&gt;. I briefly considered just writing an http handler for that but I knew that there had to be a better way. &lt;/P&gt;
&lt;P&gt;Enter WCF.&lt;/P&gt;
&lt;P&gt;It is actually incredibly easy to write REST services in .net. with WCF.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Step 1&lt;/P&gt;
&lt;P&gt;Create a new WCF service&amp;nbsp; in your website. &lt;/P&gt;
&lt;P&gt;Step 2&lt;/P&gt;
&lt;P&gt;Go to the cruft VS adds to your Web.config when creating your service and remove it and replace it with the following&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="web"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;                &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;webHttp&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Service"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;                  &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;                  &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="IService"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;                  &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="web"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="WebsiteService"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  17:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt;                 &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  19:  &lt;/SPAN&gt;                 &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="WebsiteService"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  20:  &lt;/SPAN&gt;                 &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="web"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  21:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  22:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  23:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;BR&gt;And all you have to do it is add some attributes to your service contract&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.ServiceModel;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.ServiceModel.Web;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;[ServiceContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;interface&lt;/SPAN&gt; IService&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;    [WebGet(UriTemplate = &lt;SPAN class=str&gt;"/SayHello"&lt;/SPAN&gt;, ResponseFormat = WebMessageFormat.Xml)]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; SayHello();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;    [WebGet(UriTemplate = &lt;SPAN class=str&gt;"/SayHello/{user}"&lt;/SPAN&gt;, ResponseFormat = WebMessageFormat.Xml)]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; SayHelloToUser(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; user);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;    [WebGet(UriTemplate = &lt;SPAN class=str&gt;"/SayHelloInJson/{user}"&lt;/SPAN&gt;, ResponseFormat = WebMessageFormat.Json)]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  17:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; SayHelloToUserInJson(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; user);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  19:  &lt;/SPAN&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  20:  &lt;/SPAN&gt;    [WebGet(UriTemplate = &lt;SPAN class=str&gt;"/GetPackage"&lt;/SPAN&gt;, ResponseFormat = WebMessageFormat.Json)]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  21:  &lt;/SPAN&gt;    Package GetPackage();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  22:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  23:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  24:  &lt;/SPAN&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  25:  &lt;/SPAN&gt;    [WebInvoke(Method = &lt;SPAN class=str&gt;"POST"&lt;/SPAN&gt;, UriTemplate = &lt;SPAN class=str&gt;"/PlainPost"&lt;/SPAN&gt;, ResponseFormat = WebMessageFormat.Xml,&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  26:  &lt;/SPAN&gt;        BodyStyle = WebMessageBodyStyle.Wrapped)]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  27:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; PlainPost(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; username, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; name, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; message);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  28:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;  29:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Then implement the interface and you are good to go. I'll cover consuming these with both .Net and Javascript in a later post.&lt;/P&gt;
&lt;P&gt;The attributes are where the real magic happens&lt;/P&gt;
&lt;P&gt;The &lt;A title="WebGetAttribute Class" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx"&gt;WebGet&lt;/A&gt; attribute tells WCF that this method is invoked via an HTTP Get Request.&lt;/P&gt;
&lt;P&gt;The &lt;A title="WebGetAttribute.UriTemplate Property" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.uritemplate.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.uritemplate.aspx"&gt;UriTemplate&lt;/A&gt; attribute property sets the URI of the call so on SayHello the url requested would be ~/Service.svc/SayHello&lt;/P&gt;
&lt;P&gt;The &lt;A title="WebGetAttribute.ResponseFormat Property" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.responseformat.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.responseformat.aspx"&gt;ResponseFormat&lt;/A&gt; attribute property tells the service to return either XML or Json depending on the value of the &lt;A title="WebMessageFormat Enumeration" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webmessageformat.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webmessageformat.aspx"&gt;WebMessageFormat enum&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The &lt;A title=System.ServiceModel.Web.WebInvokeAttribute href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.aspx"&gt;WebInvoke&lt;/A&gt; attribute gives you to specify the type of HTTP request you make. The default method is POST. &lt;/P&gt;
&lt;P&gt;The &lt;A title="WebInvokeAttribute.BodyStyle Property" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.bodystyle.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.bodystyle.aspx"&gt;BodyStyle&lt;/A&gt; attribute property sets the body style of the messages sent to and from the service.&lt;/P&gt;
&lt;P&gt;There you have it. Simple REST from WCF.&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6918329" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="web services" scheme="http://weblogs.asp.net/kevinisom/archive/tags/web+services/default.aspx" /><category term="WCF" scheme="http://weblogs.asp.net/kevinisom/archive/tags/WCF/default.aspx" /></entry><entry><title>More Web Development with Internet Explorer</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/09/25/more-web-development-with-internet-explorer.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/09/25/more-web-development-with-internet-explorer.aspx</id><published>2008-09-24T23:55:44Z</published><updated>2008-09-24T23:55:44Z</updated><content type="html">&lt;p&gt;I have mentioned &lt;a href="http://weblogs.asp.net/kevinisom/archive/2008/02/29/web-development-with-internet-explorer.aspx" target="_blank"&gt;previously&lt;/a&gt; some useful tools for web development for IE, and now here are a couple more.&lt;/p&gt;  &lt;h3&gt;&lt;a title="DOM Helper" href="http://www.hairy-spider.com/2006/02/24/AnnouncingDOMHelperANewAndImprovedCSSEditor.aspx" target="_blank"&gt;DOM Helper&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/MoreWebDevelopmentwithInternetExplorer_7B40/CropperCapture%5B16%5D_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="219" alt="CropperCapture[16]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/MoreWebDevelopmentwithInternetExplorer_7B40/CropperCapture%5B16%5D_thumb.jpg" width="644" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This allows you to edit the css of a page much like &lt;a title="EditCSS Extension for Firefox" href="https://addons.mozilla.org/en-US/firefox/addon/179" target="_blank"&gt;EditCSS&lt;/a&gt; for Firefox&lt;/p&gt;  &lt;h3&gt;&lt;a title="Fiddler - HTTP Debugging Proxy" href="http://www.fiddlertool.com/fiddler/" target="_blank"&gt;Fiddler&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;From the site&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&amp;quot;Fiddler is a HTTP Debugging Proxy which logs all HTTP traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP Traffic, set breakpoints, and &amp;quot;fiddle&amp;quot; with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.&amp;quot;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/MoreWebDevelopmentwithInternetExplorer_7B40/CropperCapture%5B17%5D_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="424" alt="CropperCapture[17]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/MoreWebDevelopmentwithInternetExplorer_7B40/CropperCapture%5B17%5D_thumb_1.jpg" width="546" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A cool feature of Fiddler is the ability to write &lt;a href="http://www.fiddlertool.com/Fiddler2/extensions.asp" target="_blank"&gt;extensions&lt;/a&gt; for it. Definitely worthy looking into&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://delicious.com" target="_blank"&gt;Delicious&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;And not development related but damn useful (finally) is the &lt;a href="http://delicious.com/help/installie" target="_blank"&gt;Delicious plugin for IE&lt;/a&gt;. I have a tonne of bookmarks, keeping them synced between browsers and machines used to be a nightmare. Now I just use Delicious for IE and Firefox on all my machines and my problem is solved....Now if I could just cull some of my 2456 links I have saved I'd be alright.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6640840" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Tools" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tools/default.aspx" /></entry><entry><title>Preventing simple errors with the null coalescing operator</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/09/25/preventing-simple-errors-with-the-null-coalescing-operator.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/09/25/preventing-simple-errors-with-the-null-coalescing-operator.aspx</id><published>2008-09-24T21:12:12Z</published><updated>2008-09-24T21:12:12Z</updated><content type="html">&lt;p&gt;How often have you seen code like this?&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; myAppSetting = ConfigurationManager.AppSetting[&lt;span class="str"&gt;&amp;quot;key&amp;quot;&lt;/span&gt;];&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt;(myAppSetting==&lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;     myAppSetting = &lt;span class="str"&gt;&amp;quot;MyDefaultSetting&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;Or worse yet not even do the check, then during the deploy process the appsetting doesn't get copied over to the instance and you get a null reference exception. That is not a good look.&lt;/p&gt;

&lt;p&gt;That sucks. But is preventable in code. That's when the &lt;a title="The Null-Coalescing Operator at MSDN" href="http://msdn.microsoft.com/en-us/library/ms173224.aspx" target="_blank"&gt;null coalescing operator(??)&lt;/a&gt; comes in handy.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; myAppSetting = &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;          ConfigurationManager.AppSetting[&lt;span class="str"&gt;&amp;quot;key&amp;quot;&lt;/span&gt;] ?? &lt;span class="str"&gt;&amp;quot;MyDefaultSetting&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;And that's it. A very easy way to prevent errors after deployment. Of course it's useful in other scenarios as well&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Now the story in VB isn't nearly as nice &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; myAppSetting &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt; = IIf(ConfigurationManager.AppSetting(&lt;span class="str"&gt;&amp;quot;key&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;Is&lt;/span&gt; &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;, _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="str"&gt;&amp;quot;MyDefaultSetting&amp;quot;&lt;/span&gt;, ConfigurationManager.AppSetting(&lt;span class="str"&gt;&amp;quot;key&amp;quot;&lt;/span&gt;))&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;There is a &lt;a title="VB.Net Tip: IIF is a function, not a language feature at secretgeek.net" href="http://secretgeek.net/iif_function.asp" target="_blank"&gt;gotcha with IIF&lt;/a&gt; as well because it's a function and not a language feature.&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Anytime you can code to prevent error's&amp;#160; and keep the application working it's a win. Of course make note that the default value you set could cause other errors so use appropriately.&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6640693" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Code" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Code/default.aspx" /></entry><entry><title>Testing Web Services remotely</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/08/26/testing-web-services-remotely.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/08/26/testing-web-services-remotely.aspx</id><published>2008-08-25T23:48:20Z</published><updated>2008-08-25T23:48:20Z</updated><content type="html">&lt;p&gt;I hate it when I forget something. I had one of the guys on my team today asked me how to invoke a web service remotely as he was getting an error. Well I knew right away what the problem was. But could remember the solution so I had to look and now I'm gonna put it here so it'll be easier to find next time.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;  &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;webServices&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;protocols&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HttpGet&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HttpPost&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;protocols&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;webServices&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;  &lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;Now I don't recommend this for production, but it's pretty useful for testing.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6565300" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="XML" scheme="http://weblogs.asp.net/kevinisom/archive/tags/XML/default.aspx" /><category term="web services" scheme="http://weblogs.asp.net/kevinisom/archive/tags/web+services/default.aspx" /><category term="web.config" scheme="http://weblogs.asp.net/kevinisom/archive/tags/web_2E00_config/default.aspx" /></entry><entry><title>Web Development with Internet Explorer</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/02/29/web-development-with-internet-explorer.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/02/29/web-development-with-internet-explorer.aspx</id><published>2008-02-29T04:01:00Z</published><updated>2008-02-29T04:01:00Z</updated><content type="html">&lt;p&gt;Firebug rocks. Nothing, I mean nothing beats it for debug web pages. But what do you do for problems specific to IE (most notably IE 6) Here are a list of tools I use to help cause telling the user to get a real browser is not a solution&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=E59C3964-672D-4511-BB3E-2D5E1DB91038&amp;amp;displaylang=en" target="_blank"&gt;Internet Explorer Developer Toolbar&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This toolbar provides some of the features of firebug.   &lt;br /&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B2%5D.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="154" alt="CropperCapture[2]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B2%5D_thumb.png" width="406" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://westciv.com/xray/" target="_blank"&gt;XRAY&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Is a bookmarklet that let's you see information about elements on a page.   &lt;br /&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B3%5D.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="154" alt="CropperCapture[3]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B3%5D_thumb.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.my-debugbar.com/wiki/CompanionJS/HomePage" target="_blank"&gt;Companion.JS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;An javascript debugger for IE   &lt;br /&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B4%5D.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="175" alt="CropperCapture[4]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B4%5D_thumb.png" width="324" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This may not be free in the future. Debug Bar from the same guy is also a very useful tool, but it's not free for professional use but probably worth the 59 euro if you do a lot of work with IE.&lt;/p&gt;  &lt;p&gt;And finally something while not useful for debugging but damn useful in its own right is the &lt;a href="http://www.ieforge.com/InlineSearch/HomePage" target="_blank"&gt;Inline Search for IE&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B5%5D.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="45" alt="CropperCapture[5]" src="http://weblogs.asp.net/blogs/kevinisom/WindowsLiveWriter/WebDevelopmentwithInternetExplorer_ED7D/CropperCapture%5B5%5D_thumb.png" width="644" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Hope this helps somebody out.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5880004" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Tools" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tools/default.aspx" /></entry><entry><title>Visual Basic.Net ain't half bad</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/02/29/visual-basic-net-ain-t-half-bad.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/02/29/visual-basic-net-ain-t-half-bad.aspx</id><published>2008-02-29T01:49:29Z</published><updated>2008-02-29T01:49:29Z</updated><content type="html">&lt;p&gt;There I said it.&lt;/p&gt;  &lt;p&gt;I'm a C# guy. Now about 4 years when I started with .Net I started writing in VB.Net but I quickly decided to move C#. This, despite having spent the 3+ years prior working in ASP Classic. After a little bit of C# I quickly adopted the typical C# snobbish opinion of VB. For no good reason mind you, just cause it was different.&lt;/p&gt;  &lt;h2&gt;My how things change.&lt;/h2&gt;  &lt;p&gt;I've joined a VB team and instead of trying to make the team change to C# I figured I'd just get back to VB. Also we do a lot of work with XML so it got me looking into the VB 9.0 XML features and I found that you can do things like this:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; &amp;lt;xmlns:ns=&lt;span class="str"&gt;&amp;quot;http://contacts&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; contact1 &lt;span class="kwrd"&gt;As&lt;/span&gt; XElement = _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &amp;lt;contact&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;      &amp;lt;name&amp;gt;Joe Bloggs&amp;lt;/name&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;      &amp;lt;phone type=&lt;span class="str"&gt;&amp;quot;home&amp;quot;&lt;/span&gt;&amp;gt;09-555-0144&amp;lt;/phone&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;      &amp;lt;phone type=&lt;span class="str"&gt;&amp;quot;mobile&amp;quot;&lt;/span&gt;&amp;gt;021-555-0145&amp;lt;/phone&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &amp;lt;/contact&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Okay, nifty and all, but what do you do from there...How about this?&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; phoneTypes &lt;span class="kwrd"&gt;As&lt;/span&gt; XElement = _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;  &amp;lt;phoneTypes&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;      &amp;lt;%= From phone &lt;span class="kwrd"&gt;In&lt;/span&gt; contacts...&amp;lt;phone&amp;gt; _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;          &lt;span class="kwrd"&gt;Select&lt;/span&gt; &amp;lt;type&amp;gt;&amp;lt;%= phone.@type %&amp;gt;&amp;lt;/type&amp;gt; _&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;      %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;  &amp;lt;/phoneTypes&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And that will give you the following XML&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;phoneTypes&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;home&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;mobile&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;phoneTypes&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;That's rather cool and really useful with some of the stuff I'll be working on.&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb384460.aspx" target="_blank"&gt;Overview of LINQ to XML in Visual Basic&lt;/a&gt; for more details&lt;/p&gt;

&lt;p&gt;Now, I still want to say I'm a C# guy, but I think the snickering at the mention of VB stops now.&amp;#160; &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5879512" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Code" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Code/default.aspx" /><category term="Visual Basic" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Visual+Basic/default.aspx" /><category term="XML" scheme="http://weblogs.asp.net/kevinisom/archive/tags/XML/default.aspx" /></entry><entry><title>Visual Basic.Net and NUnit Gotcha</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/02/28/visual-basic-net-and-nunit-gotcha.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/02/28/visual-basic-net-and-nunit-gotcha.aspx</id><published>2008-02-27T20:41:39Z</published><updated>2008-02-27T20:41:39Z</updated><content type="html">&lt;p&gt;I like the NUnit 2.4 &lt;a href="http://nunit.com/blogs/?p=44" target="_blank"&gt;Constraint based syntax&lt;/a&gt;. So In my new role I am having to implement Unit Testing so I decided on going with &lt;a href="http://www.nunit.org" target="_blank"&gt;NUnit&lt;/a&gt; to begin with despite my preference for &lt;a href="http://www.mbunit.com/" target="_blank"&gt;MbUnit&lt;/a&gt;. But once I got started writing my tests, I discover Is is a keyword in VB (I'm more of a C# person, but hey I'm no language bigot). I kinda freak out a little. Did I do something wrong? Forget to add something? Google a bit and still no joy. Then I remember the code examples installed with NUnit and have a look and what do you know? Is is now Iz in VB. Not exactly as clear as Is but you gotta do what you gotta do. So now in VB a Unit Test looks like this&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; NUnit.Framework&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; NUnit.Framework.SyntaxHelpers&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;lt;TestFixture()&amp;gt; _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; MyVIsualBasicSampleTests&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &amp;lt;Test()&amp;gt; _&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TestBlankForSyntax()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        Assert.That(something.IsSomething(), Iz.&lt;span class="kwrd"&gt;False&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &amp;lt;Test()&amp;gt; _&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; AnotherSampleTestForSomethingElse()&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        Assert.That(something.IsSomethingElse(), Iz.&lt;span class="kwrd"&gt;True&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;And there you go. &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5872387" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="Code" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Code/default.aspx" /><category term="Unit Testing" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Unit+Testing/default.aspx" /><category term="Visual Basic" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Visual+Basic/default.aspx" /></entry><entry><title>Web Application Projects and Profiles</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/02/28/web-application-projects-and-profiles.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/02/28/web-application-projects-and-profiles.aspx</id><published>2008-02-27T20:05:17Z</published><updated>2008-02-27T20:05:17Z</updated><content type="html">&lt;p&gt;So, I'm working on a Web Application Project in Visual Studio 2008 and I realize I don't have a strongly typed Profile object...So I Google around and find that this a Problem in Visual Studio 2005 and that Microsoft didn't fix the problem in VS 2008. Needless to say I was a little unimpressed. But I also found the &lt;a href="http://code.msdn.microsoft.com/WebProfileBuilder/Release/ProjectReleases.aspx?ReleaseId=130" target="_blank"&gt;Web Profile Builder&lt;/a&gt; at the &lt;a href="http://code.msdn.microsoft.com/" target="_blank"&gt;MSDN Code Gallery&lt;/a&gt;. I followed the &lt;a title="Instructions for installing Web Profile Builder" href="http://weblogs.asp.net/joewrobel/archive/2008/02/03/web-profile-builder-for-web-application-projects.aspx" target="_blank"&gt;instructions here&lt;/a&gt; and was away running.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5872161" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="VisualStudio" scheme="http://weblogs.asp.net/kevinisom/archive/tags/VisualStudio/default.aspx" /></entry><entry><title>Hiding a Popup Panel with JavaScript</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2008/01/29/hiding-a-popup-panel-with-javascript.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2008/01/29/hiding-a-popup-panel-with-javascript.aspx</id><published>2008-01-29T03:34:00Z</published><updated>2008-01-29T03:34:00Z</updated><content type="html">
&lt;p&gt;Had a instance where I needed to close the Popup Control with JavaScript&lt;/p&gt;
  &lt;div class="csharpcode"&gt;   
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ajax:PopupControlExtender&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="pceShowPanel"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="attr"&gt;TargetControlID&lt;/span&gt;&lt;span class="kwrd"&gt;="showPanel"&lt;/span&gt;&lt;/pre&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="attr"&gt;PopupControlID&lt;/span&gt;&lt;span class="kwrd"&gt;="popupPanel"&lt;/span&gt; &lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="attr"&gt;BehaviorID&lt;/span&gt;&lt;span class="kwrd"&gt;="popupBehavior"&lt;/span&gt;                 &lt;/pre&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;So with that on your page just hide it with hidePopup().&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;function&lt;/span&gt; Hide(){&lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    $find(&lt;span class="str"&gt;'popupBehavior'&lt;/span&gt;).hidePopup()&lt;/pre&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Of course you can show the popup as well with the showPopup() method. The real trick here is the &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/FindShortcutMethod.aspx" target="_blank" mce_href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/FindShortcutMethod.aspx"&gt;$find&lt;/a&gt; shortcut method. The &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys/ApplicationClass/SysApplicationFindComponentMethod.aspx" target="_blank" mce_href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys/ApplicationClass/SysApplicationFindComponentMethod.aspx"&gt;FindComponent&lt;/a&gt; method does just that and get's the component in this case the &lt;a href="http://asp.net/AJAX/AjaxControlToolkit/Samples/PopupControl/PopupControl.aspx" target="_blank" mce_href="http://asp.net/AJAX/AjaxControlToolkit/Samples/PopupControl/PopupControl.aspx"&gt;PopupExtender&lt;/a&gt; and allows you to call the methods associated with that control.&lt;/p&gt;

&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5672655" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="ajaxcontroltoolkit" scheme="http://weblogs.asp.net/kevinisom/archive/tags/ajaxcontroltoolkit/default.aspx" /><category term="ajax" scheme="http://weblogs.asp.net/kevinisom/archive/tags/ajax/default.aspx" /><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /></entry><entry><title>Setting Form Values Automatically with SubSonic</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2007/10/30/setting-form-values-automatically-with-subsonic.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2007/10/30/setting-form-values-automatically-with-subsonic.aspx</id><published>2007-10-30T10:04:46Z</published><updated>2007-10-30T10:04:46Z</updated><content type="html">&lt;p&gt;Tedious coding sucks. SubSonic saves lots of time. But I want it to save me more. So I've started working on a method that will fill out the controls for me so I don't have to. It's simple really. I just new() up a the model I will use and pass it to my method along with the UserControl I have my form elements in.&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetupForm&amp;lt;T&amp;gt;(Control form, T activeRecord ) &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;where&lt;/span&gt; T : AbstractRecord&amp;lt;T&amp;gt; ,&lt;span class="kwrd"&gt;new&lt;/span&gt;()&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    TableSchema.TableColumnSettingCollection settings = activeRecord.GetColumnSettings();&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TableSchema.TableColumnSetting setting &lt;span class="kwrd"&gt;in&lt;/span&gt; settings)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        Control settingControl = form.FindControl(setting.ColumnName);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (settingControl &lt;span class="kwrd"&gt;is&lt;/span&gt; TextBox)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            ((TextBox)settingControl).Text = &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                activeRecord.GetColumnValue&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(setting.ColumnName);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (settingControl &lt;span class="kwrd"&gt;is&lt;/span&gt; DropDownList)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            ((DropDownList)settingControl).SelectedValue = &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                activeRecord.GetColumnValue&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(setting.ColumnName);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The key thing is to make sure you have called EnsureChildControls() before calling this method.&lt;/p&gt;
&lt;p&gt;So in my control the code looks like&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; issueId = SubSonic.Sugar.Web.QueryString&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(&lt;span class="str"&gt;"issue"&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (issueId != 0)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    EnsureChildControls();&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    Issue issue = &lt;span class="kwrd"&gt;new&lt;/span&gt; Issue(issueId);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="rem"&gt;//BasePage inherits from System.Web.UI.Page&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    BasePage.SetupForm(&lt;span class="kwrd"&gt;this&lt;/span&gt;, issue);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;} &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now this is pretty rough and more than anything a proof of concept so your mileage may vary. But I figure this is a good place to start&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2007%2f10%2f30%2fsetting-form-values-automatically-with-subsonic.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2007%2f10%2f30%2fsetting-form-values-automatically-with-subsonic.aspx" border="0"&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4835911" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /><category term="SubSonic" scheme="http://weblogs.asp.net/kevinisom/archive/tags/SubSonic/default.aspx" /></entry><entry><title>Setting the enum from it's name</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2007/10/30/getting-the-name-of-an-enum.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2007/10/30/getting-the-name-of-an-enum.aspx</id><published>2007-10-29T17:55:46Z</published><updated>2007-10-29T17:55:46Z</updated><content type="html">&lt;p&gt;I've changed this a bit due to some comments&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;enum&lt;/span&gt; Directions&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    Up,&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Down,&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    Left,&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    Right&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; DoSomething()&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    Directions currentState =(Directions) Enum.Parse(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Directions), &lt;span class="str"&gt;"Down"&lt;/span&gt;); &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4813353" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author></entry><entry><title>Grabbing Data from a GridView on PostBack</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2007/10/29/grabbing-data-from-a-gridview-on-postback.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2007/10/29/grabbing-data-from-a-gridview-on-postback.aspx</id><published>2007-10-29T03:55:25Z</published><updated>2007-10-29T03:55:25Z</updated><content type="html">&lt;p&gt;Have you ever wanted to grab bulk data on a grid view? It's actually not that hard at all. Set the &lt;a title="DataKeys Property" href="http://msdn2.microsoft.com/d55dhytz.aspx"&gt;System.Web.UI.WebControls.GridView.DataKeys&lt;/a&gt;&amp;nbsp;Property on the Grid, then on the postback event iterate over the grid like so.&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (GridViewRow row &lt;span class="kwrd"&gt;in&lt;/span&gt; gridView.Rows) &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{ &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    DataKey data = gridView.DataKeys[row.RowIndex]; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; Id = (&lt;span class="kwrd"&gt;int&lt;/span&gt;)data.Values[&lt;span class="str"&gt;"Id"&lt;/span&gt;]; &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    TextBox myControl = row.FindControl(&lt;span class="str"&gt;"mycontrol"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; TextBox; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="rem"&gt;//do something with the data&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;} &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
And on your GridView add the DataKeys Property&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:GridView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="myGrid"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;     &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;="myDataSource"&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;     &lt;span class="attr"&gt;DataKeyNames&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4813616" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /><category term="Tips" scheme="http://weblogs.asp.net/kevinisom/archive/tags/Tips/default.aspx" /></entry><entry><title>SubSonic LoadFromPost</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2007/10/29/subsonic-loadfrompost.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2007/10/29/subsonic-loadfrompost.aspx</id><published>2007-10-28T23:01:00Z</published><updated>2007-10-28T23:01:00Z</updated><content type="html">
&lt;p&gt;I think &lt;a href="http://www.subsonicproject.com" mce_href="http://www.subsonicproject.com" target="_blank"&gt;SubSonic&lt;/a&gt; is simply amazing. It has saved me so much time and effort of writing. One little trick that it's got is the LoadFromPost method the Models inherit from the SubSonic.AbstractRecord&amp;lt;T&amp;gt; class.&lt;/p&gt;
  
&lt;p&gt;What LoadFromPost does is iterate over the the Request.Forms collection and matches the name of the form element with the corresponding&amp;nbsp; property for your Model. So what that means is no more of this.&lt;/p&gt;
  &lt;div class="csharpcode"&gt;   
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;Product prod = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product();&lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;prod.Name = name.Text;&lt;/pre&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;....&lt;span class="rem"&gt;//More code setting the properties based on the form&lt;/span&gt;&lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;prod.Save&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;So all you now have to do is this&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;Product prod = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product&lt;/pre&gt;
  
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;prod.LoadFromPost();&lt;span class="rem"&gt;//this loads up all the properties.&lt;/span&gt;&lt;/pre&gt;
  
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;prod.Save();&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Anything that saves time is a good thing, and nothing sucks more than writing tedious databinding code. Another advantage is that you don't need to use Server controls just plain html tags so you don't have to worry about ASP.Net adding all the extra naming container bits as well and that'll play nicely with any JavaScript or CSS that uses the id of an html tag.&lt;/p&gt;

&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2007%2f10%2f29%2fsubsonic-loadfrompost.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fkevinisom%2farchive%2f2007%2f10%2f29%2fsubsonic-loadfrompost.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4807819" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /><category term="SubSonic" scheme="http://weblogs.asp.net/kevinisom/archive/tags/SubSonic/default.aspx" /></entry><entry><title>Update to Ajax control toolkit breaks autocomplete</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/kevinisom/archive/2007/10/12/update-to-ajax-control-toolkit-breaks-autocomplete.aspx" /><id>http://weblogs.asp.net/kevinisom/archive/2007/10/12/update-to-ajax-control-toolkit-breaks-autocomplete.aspx</id><published>2007-10-11T20:58:22Z</published><updated>2007-10-11T20:58:22Z</updated><content type="html">&lt;p&gt;I recently updated an application to the latest version of the Ajax Control Toolkit and my AutoComplete Extender broke. It was returning the list fine. but in the dropdown the only values showed were undefined. Not cool. But after some research I changed the web service that returns the values to use the new AutoComplete Item&lt;/p&gt;  &lt;p&gt;First Version&lt;/p&gt;  &lt;p&gt;&amp;#xA0;&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;[WebMethod]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] AutoComplete( &lt;span class="kwrd"&gt;string&lt;/span&gt; prefixText, &lt;span class="kwrd"&gt;int&lt;/span&gt; count )&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(); &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; IDataReader reader = DataLayer.AutoCompleteLookup(prefixText).GetReader(); &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; results.Add(reader[0].ToString());&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;&amp;#xA0;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; results.ToArray();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;That worked fine, and I have a feeling that if the service wasn't returning numeric values like 01-145 that it might still be fine, but the service was returning values like 01-145 so I had to do this&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;div class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;[WebMethod]&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] AutoComplete( &lt;span class="kwrd"&gt;string&lt;/span&gt; prefixText, &lt;span class="kwrd"&gt;int&lt;/span&gt; count )&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(); &lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; IDataReader reader = DataLayer.AutoCompleteLookup(prefixText).GetReader(); &lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; {&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; results.Add(&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; AutoCompleteExtender.CreateAutoCompleteItem&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; (&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; reader[0].ToString(), &lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; reader[0].ToString()&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; )&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; );&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; }&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; results.ToArray();&lt;/pre&gt;

    &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt;}&lt;/pre&gt;
  &lt;/div&gt;
  &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;After that changed the AutoComplete worked again.&lt;/p&gt;

&lt;p&gt;Now that got me wondering what I could do with the AutoComplete Item that comes back. So I found a &lt;a href="http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx" target="_blank"&gt;post&lt;/a&gt; by &lt;a href="http://blogs.msdn.com/phaniraj/default.aspx" target="_blank"&gt;Phani Raj&lt;/a&gt;. The Extender Control has a property OnClientItemSelected (actually the extender has 9 OnClient events) so you could do something like this.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ajax:AutoCompleteExtender&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AutoComlete&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; &lt;span class="attr"&gt;TargetControlID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;lookupBox&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="attr"&gt;ServicePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;~/services/Lookup.asmx&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="attr"&gt;ServiceMethod&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AutoComplete&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="attr"&gt;OnClientItemSelected&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AutoComlete_Selected&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;javascript&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="kwrd"&gt;function&lt;/span&gt; AutoComlete_Selected( source, eventArgs ) {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; $get(&lt;span class="str"&gt;&amp;quot;hiddenField&amp;quot;&lt;/span&gt;).value = eventArgs.get_value();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="rem"&gt;//eventArgs also has .get_text() &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Hope this helps someone&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4525007" width="1" height="1"&gt;</content><author><name>kevinisom</name><uri>http://weblogs.asp.net/members/kevinisom.aspx</uri></author><category term="ajaxcontroltoolkit" scheme="http://weblogs.asp.net/kevinisom/archive/tags/ajaxcontroltoolkit/default.aspx" /><category term="ajax" scheme="http://weblogs.asp.net/kevinisom/archive/tags/ajax/default.aspx" /><category term="asp.net" scheme="http://weblogs.asp.net/kevinisom/archive/tags/asp.net/default.aspx" /></entry></feed>