Friday, November 16, 2012

Creating charts in ASP.NET

You can easily create ASP.NET charts in Visual Studio 2010 and VS 2012. Here are the links for getting started.

VS 2010
Visual Studio 2010 Charts

VS 2012
Visual Studio 2012 Charts

A sample pie chart

Have fun!

Friday, September 21, 2012

Randomly sort and display a set of elements using jQuery

I ran into a situation where I needed to randomly select a set of hidden elements from a web page and display only those elements. I also wanted to randomize the order of those elements so the page looked different each time. Here is a quick jQuery example.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var root = $('#tips');
            var tips = $('div.singleTip:hidden');
            $(tips).detach();
            var count = 0;
            var maxCount = 2;
            while (count <= maxCount) {
                var idx = Math.floor(Math.random() * tips.length);
                if ($(tips[idx]).is(':hidden')) {
                    $(tips[idx]).show();
                    root.append($(tips[idx]));
                    ++count;
                }
            }
        });
    </script>
    <style type="text/css">
        .singleTip {
            display: none;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div id="tips">
            <div class="singleTip">one</div>
            <div class="singleTip">two</div>
            <div class="singleTip">three</div>
            <div class="singleTip">four</div>
            <div class="singleTip">five</div>
            <div class="singleTip">six</div>
            <div class="singleTip">seven</div>
        </div>
    </form>
</body>
</html>

Sunday, August 5, 2012

I've finally got around to formalizing on a command-line parse tool for C#. And the winner is...

Command Line Parser Library

Great CSS 3 style maker

Check out this nice site for crafting CSS 3 styles with multiple browser support.

CSS 3.0 Maker

Thursday, June 21, 2012

Determine which process has a file locked - Windows 7

Are you getting that "can't delete" or "can't rename" a file because it is in use message.  On Windows 7 you can use the Resource Monitor (just type the name into the Start search box to find it) to easily find out which process has a file locked.

Start the Resource Monitor and switch to the CPU tab.  Just type the file name into the Associated Handles search box and you will be able to see which processes have matching file names locked.  To kill the process, just right-click and choose "End Process".

Easy as pie and all part of Windows 7.


Tuesday, June 12, 2012

Better regular expression for phone numbers (multiple formats)

I'm often surprised at how often websites only accept a specific format for phone number input (U.S.) so I thought I would post a more flexible input format.

We want to allow users to enter phone numbers in formats like:

(123) 456-7890
123-456-7890
123.456.7890
1234567890

Using a regular expression, we can allow all these formats and more.


^\s*[(]?(?<AreaCode>\d{3})[)]?(\s*|[.-])(?<Prefix>\d{3})(\s*|[.-])?(?<LineNumber>\d{4})\s*$

Notice that we specify regular expression group names to easily pick up the phone number parts. In C#, this can be done like:

Code:
string prefix = match.Groups["Prefix"].Value;

Finally, here the some C# code to kick things off.

Code:
Regex rePhone = new Regex(@"^\s*[(]?(?<AreaCode>\d{3})[)]?(\s*|[.-])(?<Prefix>\d{3})(\s*|[.-])?(?<LineNumber>\d{4})\s*$");
Match match = rePhone.Match("123.456.7890");
Console.WriteLine(match.Success);

Monday, June 11, 2012

Monday, May 21, 2012

Ever want to see SQL JOIN statements visually? Let's assume we have two tables, Person and Pet.

Click on the image below for a full view.

Tuesday, April 10, 2012

Monday, April 2, 2012

Nice cheat sheet on many HTML5 and CSS3 features

Here is a nice cheat sheet for some of the more requested items related to HTML5 and CSS3.  Not too bad.

Stories In Flight

Sunday, April 1, 2012

ASP.NET generic content box with title and body

Here is a quick example of creating a simple ASP.NET web control that allow you to have a region/box that contains a title and body where each of three elements can each have their own CSS class.

You can use the content box in a web page like:

Code:
using System.Web.UI.WebControls;

namespace CarverPainting
{
   public class ContentBox : Panel
   {
      public string CssClassBody
      {
         get { return base.CssClass; }
         set { base.CssClass = value; }
      }

      public override string CssClass
      {
         get
         {
            return ViewState["CssClassMain"] == null ? string.Empty : ViewState["CssClassMain"].ToString();
         }

         set
         {
            ViewState["CssClassMain"] = value;
         }
      }

      public string CssClassTitle
      {
         get
         {
            return ViewState["CssClassTitle"] == null ? string.Empty : ViewState["CssClassTitle"].ToString();
         }

         set
         {
            ViewState["CssClassTitle"] = value;
         }
      }

      public string Title
      {
         get
         {
            return ViewState["Title"] == null ? string.Empty : ViewState["Title"].ToString();
         }

         set
         {
            ViewState["Title"] = value;
         }
      }

      protected override void Render(System.Web.UIHtmlTextWriter writer)
      {
         bool hasClass = !string.IsNullOrWhiteSpace(CssClass);
         bool hasClassTitle = !string.IsNullOrWhiteSpace(CssClassTitle);
         bool hasClassBody = !string.IsNullOrWhiteSpace(CssClassBody);

         // contentbox class
         writer.Write("<div{0}>", hasClass ? string.Format(" class=\"{0}\"", CssClass) : string.Empty);

         if (!string.IsNullOrWhiteSpace(Title))
         {
            writer.Write("<div{0}>{1}</div>", hasClassTitle ? string.Format(" class=\"{0}\"", CssClassTitle) : string.Empty, Title);
         }

         base.Render(writer);

         // contentbox class
         writer.Write("</div>");
      }
   }
}

Using dotlesscss with Visual Studio and IIS

I've started to use LESS the dynamic stylesheet language with Microsoft's ASP.NET.  For starters, it really does help write and maintain stylesheets.  The .NET version can be downloaded at http://www.dotlesscss.org/.

I did however run into an issue when I deployed my development code to a production server.  It turns out that the Visual Studio 2010 web server handles the dotlesscss DLL differently from IIS 7.5.  In a nutshell, to use dotlesscss in both environments (local, production) without having to made changes to one of the environments the setup I use is:
  1. Set my web project to use IIS Express (separate download from Microsoft).
  2. Add the following items to my web.config file
xml version="1.0" encoding="utf-8"?>

<configuration>
   <configSections>
      <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
   configSections>
   <system.web>
      <compilation debug="true" targetFramework="4.0" />
      <pages>
         <controls>
            <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
         controls>
      pages>
   system.web>
   <system.webServer>
      <handlers>
         <add name="dotless" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.less.css" verb="*"/>
      handlers>
   system.webServer>
   <dotless minifyCss="false" cache="false" />
configuration>


Wednesday, February 29, 2012

Why does copy/paste not work with Remote Desktop

So what do I do when clipboard stops working when you are using Windows Remote Desktop?

Fixing the issue is pretty straightforward and involves a few basic steps.
  1. Load up task manager (right click taskbar and select Task Manager)
  2. Go to the Processes Tab
  3. Select rdpclip.exe
  4. Click End Process
  5. Go to the Application Tab
  6. Click New Task
  7. Type rdpclip
  8. Click OK

That should get things going again.

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...