Blog Index > General > ASP.net Utils File

ASP.net Utils File

I've just uploaded the latest version of the ASP.Net toolbox (version 2.0). This is a small .cs file that you can put in your app_code folder and contains some really useful helper functions

The toolbox file contains the following helper static functions:

  1. isNumeric - evaluates whether a string is a number
  2. isDate - tests whether a string is a valid date
  3. isValidEmail - checks whether a string conforms to a valid email address format
  4. isValidURL - checks whether a string is a valid url
  5. CreateRandomPassword - generates a random password
  6. CountStringOccurrences - counts the number of times a pattern appears in a string
  7. GetIP - returns the ip address of a visitor.
  8. FindControlRecursive - Recursive find control for HTMLGenericControls - you can modify this method to other types of controls if required.

Download the toolbox helper file here: http://www.mykeblack.com/data/files/mykeblack.txt (right click on this link and select 'save as')

(Important: once you have downloaded the text file, rename it to 'mykeblack.cs' - Due to security restritions, you cannot download .cs files from a windows server.)

To use the toolbox for your asp.net page, do the following:

  1. Copy the file into your app_code folder
  2. At the top of your .cs page (or your .aspx page if you are not using a separate code behind page) reference the namespace like this:

         using MykeBlack;
     
  3. In your code, call the functions eg like this:

    string myString = "1234567";
    if ( ToolBox.IsNumeric(myString,true) {
        // myString is a valid number
    }
Categories: General13 April 2011Log in to add new posts