Tuesday, May 24, 2011

Validate the calender control dates using javascript

Hi,

For this use the following javascript methods.

function ReturnDate(strDt)
{
var str = strDt;
var posn = str.indexOf("/");
var dd = str.substr(0,posn);
var str1 = str.substr(posn+1);
posn = str1.indexOf("/");
var strMm = str1.substr(0,posn);
if(strMm.length==1)
{
strMm="0"+ strMm;
}
var mm=strMm
var yy = str1.substr(posn+1);
if(mm=="01") mm=0;
else if(mm=="02") mm=1;
else if(mm=="03") mm=2;
else if(mm=="04") mm=3;
else if(mm=="05") mm=4;
else if(mm=="06") mm=5;
else if(mm=="07") mm=6;
else if(mm=="08") mm=7;
else if(mm=="09") mm=8;
else if(mm=="10") mm=9;
else if(mm=="11") mm=10;
else if(mm=="12") mm=11;
var ReturnDate = new Date(yy,mm,dd)
return ReturnDate;
}

function GetMonth(intMonth){
var MonthArray = new Array("01", "02", "03",
"04", "05", "06",
"07", "08", "09",
"10", "11", "12");
return MonthArray[intMonth];
}



function ValidateDates()
{

var otxtFromDate = document.getElementById('<%= txtFrom.ClientID %>')

var otxtToDate = document.getElementById('<%= txtTo.ClientID %>')

var toDate = otxtToDate.value;
var fromDate = otxtFromDate.value;

var currDate=new Date();

var currYear=currDate.getFullYear();


var currDay=currDate.getDate();

var currMonth=GetMonth(currDate.getMonth());

currDate=currDay+"/"+currMonth+"/"+currYear;

if(toDate != null && toDate != '')
{
if(ReturnDate(toDate) {

otxtToDate.focus();

return false;
}
}
if(fromDate != null && toDate != null && fromDate != '' && toDate != '')
{
if(ReturnDate(fromDate)>ReturnDate(toDate))
{

otxtToDate.focus();

return false;
}
}

return true;
}

Clear the File upload control value using Javascript

Hi,

If you want clear the file upload control value use the following code.

// To Clear the value in File Upload(For IE and Firefox)
var oFileUpload=document.getElementsByName('<%=fuUserList.UniqueID%>')[0];
oFileUpload.value="";
var oFileUpload2= oFileUpload.cloneNode(false);
oFileUpload2.onchange= oFileUpload.onchange;
oFileUpload.parentNode.replaceChild(oFileUpload2,oFileUpload);

Validate file format(.xls or .xlsx) using File upload control using Javascript

Hi,

If you want the validate file type using the file upload control means like the wheather it is .doc or .xls or etc., using Javascript

fuUserList -- File upload control

var fuData = document.getElementById('<%=fuUserList.ClientID%>');
var fileUploadPath = fuData.value;

var extension = fileUploadPath.substring(fileUploadPath.lastIndexOf('.')
+ 1).toLowerCase();

if (extension == "xls" || extension == "xlsx")
{
return true; // Valid file type
}
else
{
document.getElementById('<%=divExcelError.ClientID%>').style.display = "block";
return false; // Not valid file type
}

Tuesday, May 3, 2011

Copy the XML Document

Hi,

The copy of XML documnet is different from our normal objects. Because while coping the XML documnet it is coping with ref obeject. Means

XMLDocument obj1 = "Some XML documnet or XML document obeject"

XMLDocument obj2 = obj1;

If you make any changes for obj2, same thing will reflect in obj1 also. Because it is having the ref while copying. To avoid this type problems use this for coping

obj2 = (XmlDocument)obj1 .Clone();

It's works better!!