Jquery Plugin to only allow numeric input..

Ok.. so this is my first Jquery Plugin – VERY SIMPLE…

All it does is attach to the keydown of any element it is attached to and look to see if the key being pressed is numeric via a regular expression. Nothing fancy. no periods, no commas, no currency formatting.

Useful for making sure credit card numbers or bank account numbers are being entered correctly in a web page.

(function($) {
    $.fn.PreventNonNumeric = function() {
        $(this).keypress(
            function(x) {
                if (x.key.replace(/\D/, "") == ""|| x.key === "Spacebar")
                { x.preventDefault(); }
            }
        );

        return this;
    };
})(jQuery, event);

Attach to an element as

$("#Text1").PreventNonNumeric();

 

 

How to copy files from One Project to another during build – C#

A couple of key points.

  • There are a some special variables you can use to aid you.
    $(SolutionDir) and $(ProjectDir) These will always resolve to where the project is sitting and remove you need to have to script out the entire path.
  • Xcopy is the tool you need to do the copy, but at the end of the command you need to add the /Y parameter to ensure you don’t exit with “code 2″
  • The Place you need to add this to make sure the copy takes place is the “Build Events” tab of one of you solutions project directories

 

xcopy “$(SolutionDir)ControlProject\*.ascx” “$(ProjectDir)UserControls\” /Y

IN the above example, all ascx files are copied from a directory under the Solution (in my case a project that contains a number of UserControls) to the local project’s UserControls directory.

The /Y specifying that we will overwrite any existing files/

Rebuilding the UMBRACO Undex’s

There is an off chance that your index files in UMBRACO ( umbraco.config ) may become corrupt. If this is the case there is a nice built-in utilitie that can be used to rebuild all the index’s and fix the issues that your site is experiencing.

add the following to your website’s root address “Umbraco/dialogs/republish.aspx?xml=true”

e.g. if the site was http://www.someurl.com you would enter http://www.someurl.com/Umbraco/dialogs/republish.aspx?xml=true

Follow the prompts.

I found myself having to use this to fix a problem where the Dynamic menus were adding nodes that didn’t exist and breaking links on nodes that did.

Quick and easy fix

Well done umbraco team.

 

CMS Systems.. (UMBRACO)

I have reciently started looking at what i feel to be a superior CMS system that is both intuative and powerfull. It’s name is UMBRACO and is based on the .net framework. To make learning the system easy, they have a great series of video tutorials that will allow a dotnet developer to quickly take advantage of this platform and end users to do much the same.

From the developers perspective after you have loaded the site on your system I would recomend the following videos (free) – it is also worth mentioning that a lot of the videos have tutorial documents that are linked to them at the bottom right hand corner.. These are defniitely worth grabbing as they contain sample code used in the tutorial and can help to jump start understanding.

So.. in order of what makes sense of you are thinking about creating a “Custom” umbraco installation.

(start here - select free to eliminate videos that you cant view – but it is worth getting the full series.. I would just review all the free content before you purchase your subscription..)

  1. http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/building-the-cws-site/creating-the-basic-structure/TVPlayer

PS.. as i work through the tutorials and gain a greater undrstanding this page will get updated (probably quite quickly)

Rob.

Dealing with Mulitple (same key) Query String items in C#

Today i bumped into a problem that was quite easy in the (good old) days of traditional ASP.

Our webapplication needed to pass multiple id’s to a page in it’s query string. The query string was built by simply “joining” a list of id’s and passing that into the url.

var QString =String.Join("&id=", item.OrderConfirmationData.VendorOrders.Select(x => x.VendorOrderNumber))

This would build a query string that looked something like
http://localhost:36165/WebSite1/querystring.aspx?id=1&id=23&id=43&id=103

Reading it back via server side code using somehting like to string returned a comma seperated string. (that might not have been bad if some of the values had comma’s in them. :)

e.g. 1,23,43,103

This inturn caused us to split the results to and array based on the comma. arghhh that was when the fun started.

So.. the solution.

The querystring object in .net has a .GetValues method. If you pass in the Parameter name, it return a string array of values..

At that point parcing the values is easy and clean. e.g.


var values = Request.QueryString.GetValues("id");
foreach (var item in values)
{
litSPLIT.Text += item + "<br />";
}