January 2009 - Posts

Running Multiple Version of IE in same System

If you ever been working on layout and design of website then you may need to test the layout and rendering of the website in different browser, like IE 7, IE 6, IE 5.5, FireFox, Opera, etc.

But normally it is not possible to install multiple version IE in same system. So to get through this limitation of Windows, I found the following program using this you can run multiple version of IE (IE 7.0, 6.0, 5.5, 5.1, 4.0, 3.0) in the same System,

Download it

Normally this installer will not work with Windows Vista,

Follow the progress of running Internet Explorer 6 natively on Windows Vista here!

You can get more details in Treadsoft Homepage

I hope this will help you.

Posted by bmdayal | with no comments
Filed under: ,

Javascript Date Comparision using CustomValidator And String to Date Conversion using JavaScript

This function calculates the difference between the two Date, and Validate it,

I used this function to validate the difference between the From Date and To Date for not more then 366 days(to cover the leap year also) or less then 0,

This function is called through the CustomValidator of ASP.NET, but you can also use this without the CustomValidator.

 

<asp:CustomValidator runat="server" ID="custDateValidator" 
  ClientValidationFunction="CompareDates" Display="Dynamic" 
  ErrorMessage="The number of date to be included in report must be between 1 and 366"> 
</asp:CustomValidator>

 

This piece of code also depicts how we can convert the String to DateTime, because in my form I am taking the Dates from two HTML TextBoxes, which by default is String, so I had to write seperate piece of code which will convert String to DateTime.

 

<script language="JavaScript"> 
function CompareDates(source, args) { 
    var fromDate = new Date(); 
    var txtFromDate = document.getElementById("txtDateFrom").value; 
    var aFromDate = txtFromDate.split("/"); 

    /*Start 'Date to String' conversion block, this block is required because javascript do not provide any direct function to convert 'String to Date' */

    var fdd = aFromDate[0]; //get the day part 
    var fmm = aFromDate[1]; //get the month part 
    var fyyyy = aFromDate[2]; //get the year part 

    fromDate.setUTCDate(fdd); 
    fromDate.setUTCMonth(fmm-1); 
    fromDate.setUTCFullYear(fyyyy); 

    var toDate = new Date(); 
    var txtToDate = document.getElementById("txtDateTo").value; 
    var aToDate = txtToDate.split("/"); 
    var tdd = aToDate[0]; //get the day part 
    var tmm = aToDate[1]; //get the month part 
    var tyyyy = aToDate[2]; //get the year part 

    toDate.setUTCDate(tdd); 
    toDate.setUTCMonth(tmm-1); 
    toDate.setUTCFullYear(tyyyy); 

    //end of 'String to Date' conversion block 
    var difference = toDate.getTime() - fromDate.getTime(); 
    var daysDifference = Math.floor(difference/1000/60/60/24); 
    difference -= daysDifference*1000*60*60*24;

    //if diffrence is greater then 366 then invalidate, else form is valid 
    if(daysDifference > 366 daysDifference < 0) 
        args.IsValid = false; 
    else 
        args.IsValid = true; 
} 

</script> 

Posted by bmdayal | 1 comment(s)
Filed under: ,

Happy New Year 2009 !!!

I wish a Very Happy New Year 2009  to all the readers and members of http://dotnetslackers.com !!!

May this coming new year will bring you success, joy and a great future ahead.

 

Cheers

~Brij Mohan

Posted by bmdayal | with no comments
Filed under: ,

Visual Studio .NET Hot Fixes


Microsoft has moved all Visual Studio and .NET hot fixes to a single location on MSDN Code Gallery. Here is a link that pulls up all the hot fixes:


http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?TagName=Hotfix
They used to be over at the Connect site but you had to log in, and they were somewhat hard to find. Now you can get them all from the link above without being logged in.
Posted by bmdayal | with no comments

IsNumeric Function in C#

VB.NET has lots of functions that C# developers have to create manually.

Out of which I am providing here the different alternatives of IsNumeric function of VB.NET in C#

Using Parse

static bool IsNumeric(string s)

{

    try

    {

        Int32.Parse(s);

    }

    catch

    {

        return false;

    }

    return true;

}

Using Double.TryParse

(C# 2.0 and above)

static bool IsNumeric(object expression)

{

    if (expression == null)

        return false;

    double number;

    return Double.TryParse(Convert.ToString(expression,   CultureInfo.InvariantCulture),

        System.Globalization.NumberStyles.Any, NumberFormatInfo.InvariantInfo, out number);

}

Using Regular Expression

bool IsNumeric(string value)

{

    Regex regxNumericPatters = new Regex("[^0-9]");

    return !regxNumericPatters.IsMatch(value);

}

OR

static bool IsNumeric(string inputString)

{

    return Regex.IsMatch(inputString, "^[0-9]+$");

}

Using Char

static bool IsNumeric(string numberString)

{

    foreach (char c in numberString)

    {

        if (!char.IsNumber(c))

        return false;

    }

    return true;

}

I hope this will help you, if you have more ideas then do write comments.

Posted by bmdayal | with no comments
Filed under: ,