Thursday 15 May 2008

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>

I Hope this will Help.

Share:

Thursday 8 May 2008

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.

Share:

Sunday 4 May 2008

Visual Studio 2008 and .NET 3.5 Overview and Tutorials (Links)

This post will provide a quick overview of Visual Studio.NET 2008 and useful links which will give a depth understanding of of .NET 2008, Framework 3.0 and Framework 3.5.

Visual Studio 2008 was first shipped on November 2007, you can download the 90 day trial version from here

Some of the important difference and new features can be found in the link

in ASP Alliance this link will give you enough basic concepts to kick start your journey into .NET 2008, once you get through this basics, following are the useful MSDN links which will provide you with the WPF, WCF and WF (Workflow foundations) from basics to advance level programming.

Windows Communication Foundation

WPF Tutorial

WF Foundation

ASP.NET MVC Source Code

If you have windows live id (Hotmail account), and good broadband speed, you can try hands on MSDN Virtual Lab

Remember there are some or lots of features in WPF programming which requires Windows Vista OS, but don't get disappointed if you are using Windows XP SP2, you can download and install Microsoft Virtual PC at

http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx.

And download free copies of Windows Vista from http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en

This VPC image will expire on July 3, 2008.

If you have missed Virtual Tech days from Microsoft for Microsoft SQL Server 2008 and Microsoft Visual Studio 2008, you can download the Session Recordings and Presentations from the following links

http://www.microsoft.com/india/virtualtechdays/

If this link is not working then post you email in my the comments, I have downloaded presentations in my local system, I will try to send you.

My target of this post is for beginners who keep on hunting in Google for various links of .NET 2008, I tried to collect few good ones one single place, hope this will help and keep posted me or others if you have good links, in the comments.

Related post :

Difference Between .NET Framework 2.0 and .NET Framework 3.0

Ajax Error in Visual Studio 2008

Using LINQ with ASP.NET

Share: