Monday, June 27, 2011

ASP.NET MVC3 has a few quirks

http://aspnet.codeplex.com/workitem/7629

Ack!  Seems like this shouldn't have happened. 

To correct, you have to do the following:

Give your select list the "Required" attribute.
Once the page loads, in jQuery, assign the data-val attribute and the data-val-message attributes.

Microsoft, this is not good!

Tuesday, June 7, 2011

Team Foundation Server 2010 isn't friendly for certain items...

It seems as if this is a normally recurring issue with build automation and Team Foundation Server 2010 specifically.  Utilizing Team Foundation Server's build automation, it takes the *.sln and *.csproj files and utilizes that to create the output binaries as expected.  What is unfortunate is that the .Net SDK doesn't have everything that you need to handle build automation on a build server, so you're forced to do one of 2 things:
  1. Deploy VS.Net 2010 on your build server(s)
  2. Copy the files from c:\{Program Files x86}\MSBuild\Microsoft\VisualStudio\... to your build machine.
Honestly, both solutions break the fundamental rules of using a build automation server, IMHO.  Completely disappointed Microsoft! I think that I'll be writing ScottGU or someone else to see if they have a better solution to handle this case, as it's simply a poor "workaround" solution.

Thursday, June 2, 2011

Textarea Autoexpand Javascript code.

As part of a project for a consulting job I'm on, the need we had was to give a forever expanding text area on the html form.  This is the javascript I wrote to do just that.  I'm sharing it because mainly, I think it's cool!

I should have documented how this works. What you'll do in the Html is to define a text area (could be an asp TextBox with its mode set to Multiple, or a generic TextArea tag... either way, they render out the same.) and you'll add an attribute called expandable and set its value equal to True.  From there, reference jQuery in your header, and this code should work for you as-is.

Have at it, and comment if you see where I could improve in some way.

          function formatPage() {
            $(document).find('*[expandable]').keyup(function () {
                var height = 0;
                var existingHeight = this.style.height;
                var lines = this.value.split('\r');
                this.style.height = '';
                for (x = 0; x < lines.length; x++) {
                    var lengthOverflow = lines[x].length % this.cols;

                    height = height + (14 * (((lines[x].length - lengthOverflow) / this.cols)));
                    if (lengthOverflow > 0) {
                        height = height + 14;
                    }
                }

                if (height == 0) {
                    height = 14;
                }

                if (existingHeight != height) {
                    this.style.height = height + 'px';
                }
            });

            $(document).find('*[expandable]').keyup();
        }

        $(document).ready(function () {
            formatPage();
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        });


        function endRequestHandler(sender, args) {
            formatPage();
        }