মঙ্গলবার, ২৩ নভেম্বর, ২০১০

Overwride Required field validator display method

$(document).ready(function() {
if (typeof (ValidatorUpdateDisplay) != "undefined") {
OriginalValidatorUpdateDisplay = ValidatorUpdateDisplay;
ValidatorUpdateDisplay = function(val) {
OriginalValidatorUpdateDisplay(val);
//This is our custom overwride method.
UpdateCSS(val);
}
}
});

function UpdateCSS(val) {
try {
if (val.isvalid == false) {
$(val).parent().children().addClass('alert');
}
else {
$(val).parent().children().each(function(i) {
if ($(this).hasClass('alertMessege')==false) {
$(this).removeClass('alert');
}
});
}
}
catch (e) { }
}

সোমবার, ১২ এপ্রিল, ২০১০

Vertical and horizontal align text in div

<div style="border: 1px solid red; height: 200px; width: 400px; text-align: center; display: table-cell; vertical-align: middle;">
This is some text in a div element!
</div>


This is some text in a div element!

সোমবার, ৫ এপ্রিল, ২০১০

Javascript date validation function

function validateDate(strValue) {
/************************************************
DESCRIPTION: Validates that a string contains only
valid dates with 2 digit month, 2 digit day,
4 digit year. Date separator can be ., -, or /.
Uses combination of regular expressions and
string parsing to validate date.
Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
strValue - String to be tested for validity

RETURNS:
True if valid, otherwise false.

*************************************************/
var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

//check to see if in correct format
if (!objRegExp.test(strValue))
return false; //doesn't match pattern, bad date
else {
var strSeparator = strValue.substring(strValue.length - 5, strValue.length - 4);
var arrayDate = strValue.split(strSeparator);
var arrayLookup = new Array (0,31,0,31,30,31,30,31,31,30,31,30,31);
var intDay = parseInt(arrayDate[1], 10);
var intMonth = parseInt(arrayDate[0], 10);
//check if month value and day value agree
if (arrayLookup[intMonth] != null) {
if (intDay <= arrayLookup[intMonth] && intDay != 0)
return true; //found in lookup table, good date
}
if (intMonth == 2) {
var intYear = parseInt(arrayDate[2]);
if (intDay > 0 && intDay < 29) {
return true;
}
else if (intDay == 29) {
if ((intYear % 4 == 0) && (intYear % 100 != 0) ||
(intYear % 400 == 0)) {
// year div by 4 and ((not div by 100) or div by 400) ->ok
return true;
}
}
}
}
return false; //any other values, bad date
}

বৃহস্পতিবার, ১ এপ্রিল, ২০১০

Recursive sql with parent child relationship in sql server.

If i have a table name Document and its fields are ID, Name and ParentID

than my sql query will look like

WITH Temp_Doc(ID,ParentID,Name,itteration) AS
(
SELECT ID,ParentID,Name,0 FROM Document WHERE ID = 570
UNION ALL SELECT b.ID, b.ParentID, b.Name, itteration +1
FROM Temp_Doc AS a, Document AS b
WHERE a.ID = b.ParentID
)
SELECT * FROM Temp_Doc OPTION (MAXRECURSION 500);