Monday, October 12, 2009

Path

Making Sense of ASP.NET Paths
Full URL : http://localhost:2000/virtual_dir/myrep/page.aspx?q=qvalue
Original Path















































































Request.ApplicationPath :

/virtual_dir

Request.CurrentExecutionFilePath :

/virtual_dir/myrep/page.aspx

Request.FilePath :

/virtual_dir/myrep/page.aspx

Request.Path :

/virtual_dir/myrep/page.aspx

Request.PhysicalApplicationPath :

d:\Inetpub\wwwroot\Websitename\virtual_dir\

Request.QueryString :

/virtual_dir/myrep/page.aspx?q=qvalue

Request.Url.AbsolutePath :

/virtual_dir/myrep/page.aspx

Request.Url.AbsoluteUri :

http://localhost:2000/virtual_dir/myrep/page.aspx?q=qvalue

Request.Url.Host :

localhost

Request.Url.Authority :

localhost:2000

Request.Url.LocalPath :

/virtual_dir/myrep/page.aspx

Request.Url.PathAndQuery :

/virtual_dir/myrep/page.aspx?q=qvalue

Request.Url.Port :

2000

Request.Url.Query :

?q=qvalue

Request.Url.Scheme :

http

Request.Url.Segments :

/


virtual_dir/


myrep/


page.aspx

Wednesday, October 7, 2009

Custom PrimaryKey Based on IdentityValue

 
CREATE TABLE [dbo].[PrimaryKeyTest](
[ID] [int] IDENTITY (1,1),
[PKV] [nchar](50) NOT NULL
) ON [PRIMARY]

GO


DECLARE @CustomPKV NVARCHAR(50)

SELECT @CustomPKV = (
CASE WHEN (ISNULL(MAX(Id), -1) = -1) THEN 1
WHEN MAX(Id) >= 1 THEN MAX(Id) + 1
END
)
FROM [dbo].[PrimaryKeyTest]

PRINT @CustomPKV

INSERT INTO [dbo].[PrimaryKeyTest] (PKV) VALUES(@CustomPKV)


SELECT ID, PKV FROM [dbo].[PrimaryKeyTest]


--To CHAR DATA TYPE 'R' + CAST(
--(CASE WHEN (ISNULL(MAX(Id), -1) = -1) THEN 1
-- WHEN MAX(Id) >= 1 THEN MAX(Id) + 1
--END) AS VARCHAR)

Thursday, October 1, 2009

Numeric Validation in Javascript

/*
NUMERIC
prefix --> For number of digits before .(Period)
If you didn't give the period also it allows only the digits that given in the prefix part

suffix --> For the number of digits after the .(Period)

NumberOnly
If we specify suffix as 0 it allows only integer
*/

  
function NumericValidation(ctrlName, e, prefix, suffix) {

var evt = e || window.event;
var code = e.charCode ? e.charCode : e.keyCode;
var EndKey = 35;
var HomeKey = 36;
var NumeriPeriodKey = 110;
var PeriodKey = 190;
if (e.shiftKey || e.ctrlKey) {
return false;
}


//debugger;
// IE
if (evt.type == 'keydown') {

if ((code == EndKey || code == HomeKey || code == 37 || code == 38 || code == 39 || code == 40 || code == 9)) {
return true;
}

if (code == 46 || code == 8) {
var val = ctrlName.value;
var pos = val.indexOf('.');
var lenofBox = val.length;

if (code == 8) {
//Since back key deletes backward
if (doGetCaretPosition(ctrlName) == (pos + 1)) {

ctrlName.value = val.substring(0, pos)
}
else {
return true;
}
}
else (code == 46)
{
//Since del key deletes forward
if (doGetCaretPosition(ctrlName) == pos) {

ctrlName.value = val.substring(0, pos)
}
else {
return true;
}
}
}

if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) || (code == PeriodKey || code == NumeriPeriodKey)) {

var val = ctrlName.value;

if (val != "") {
var pos = val.indexOf('.');
var lenofBox = val.length;

//To allow only int
if ((suffix == 0) && (code == PeriodKey || code == NumeriPeriodKey)) {
return false;
}

//if already period is available
if ((code == PeriodKey || code == NumeriPeriodKey) && (pos > -1)) {
return false;
}

//if prefix reaches and the current one is not period the stop the event
if ((pos == -1 && lenofBox == prefix) && (code != PeriodKey && code != NumeriPeriodKey)) {
return false;
}

if (doGetCaretPosition(ctrlName) > pos) {

if (pos > -1) {
var decSting = val.substring(pos + 1, lenofBox + 1);
// debugger;
//alert(doGetCaretPosition(document.getElementById('TextBox1')));
if (decSting.length == suffix) {
return false;
}
}
}
else if (pos >= prefix) {
return false;
}

}

// alert(document.getElementById('TextBox1').value + String.fromCharCode(evt.keyCode));
return true;
}
else {
// alert(document.getElementById('TextBox1').value);
return false;
}
}
else if (evt.type == 'keypress') {

if ((code == 37 || code == 38 || code == 39 || code == 40) || (code == 46 || code == 8 || code == 9)) {
return true;
}

if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) || (code == PeriodKey || code == NumeriPeriodKey)) {

var val = ctrlName.value;

if (val != "") {
var pos = val.indexOf('.');
var lenofBox = val.length;

//To allow only int
if ((suffix == 0) && (code == PeriodKey || code == NumeriPeriodKey)) {
return false;
}

//if already period is available
if ((code == PeriodKey || code == NumeriPeriodKey) && (pos > -1)) {
return false;
}

//if prefix reaches and the current one is not period the stop the event
if ((pos == -1 && lenofBox == prefix) && (code != PeriodKey || code != NumeriPeriodKey)) {
return false;
}

if (doGetCaretPosition(ctrlName) > pos) {

if (pos > -1) {
var decSting = val.substring(pos + 1, lenofBox + 1);
// debugger;
//alert(doGetCaretPosition(document.getElementById('TextBox1')));
if (decSting.length == suffix) {
return false;
}
}
}
else if (pos >= prefix) {
return false;
}
}

// alert(document.getElementById('TextBox1').value + String.fromCharCode(evt.keyCode));
return true;
}
else {
// alert(document.getElementById('TextBox1').value);
return false;
}
}
}

function doGetCaretPosition(ctrl) {
var CaretPos = 0; // IE Support
if (document.selection) {
ctrl.focus();
var Sel = document.selection.createRange();
Sel.moveStart('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart;
return (CaretPos);
}

Numeric Validation in Javascript





/* Babu Kumarasamy
NUMERIC
prefix --> For number of digits before .(Period)
If you didn't give the period also it allows only the digits that given in the prefix part

suffix --> For the number of digits after the .(Period)

NumberOnly
If we specify suffix as 0 it allows only integer
*/


function NumericValidation(ctrlName, e, prefix, suffix) {

var evt = e || window.event;
var code = e.charCode ? e.charCode : e.keyCode;
var EndKey = 35;
var HomeKey = 36;
var NumeriPeriodKey = 110;
var PeriodKey = 190;
if (e.shiftKey || e.ctrlKey) {
return false;
}


//debugger;
// IE
if (evt.type == 'keydown') {

if ((code == EndKey || code == HomeKey || code == 37 || code == 38 || code == 39 || code == 40 || code == 9)) {
return true;
}

if (code == 46 || code == 8) {
var val = ctrlName.value;
var pos = val.indexOf('.');
var lenofBox = val.length;

if (code == 8) {
//Since back key deletes backward
if (doGetCaretPosition(ctrlName) == (pos + 1)) {

ctrlName.value = val.substring(0, pos)
}
else {
return true;
}
}
else (code == 46)
{
//Since del key deletes forward
if (doGetCaretPosition(ctrlName) == pos) {

ctrlName.value = val.substring(0, pos)
}
else {
return true;
}
}
}

if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) || (code == PeriodKey || code == NumeriPeriodKey)) {

var val = ctrlName.value;

if (val != "") {
var pos = val.indexOf('.');
var lenofBox = val.length;

//To allow only int
if ((suffix == 0) && (code == PeriodKey || code == NumeriPeriodKey)) {
return false;
}

//if already period is available
if ((code == PeriodKey || code == NumeriPeriodKey) && (pos > -1)) {
return false;
}

//if prefix reaches and the current one is not period the stop the event
if ((pos == -1 && lenofBox == prefix) && (code != PeriodKey && code != NumeriPeriodKey)) {
return false;
}

if (doGetCaretPosition(ctrlName) > pos) {

if (pos > -1) {
var decSting = val.substring(pos + 1, lenofBox + 1);
// debugger;
//alert(doGetCaretPosition(document.getElementById('TextBox1')));
if (decSting.length == suffix) {
return false;
}
}
}
else if (pos >= prefix) {
return false;
}

}

// alert(document.getElementById('TextBox1').value + String.fromCharCode(evt.keyCode));
return true;
}
else {
// alert(document.getElementById('TextBox1').value);
return false;
}
}
else if (evt.type == 'keypress') {

if ((code == 37 || code == 38 || code == 39 || code == 40) || (code == 46 || code == 8 || code == 9)) {
return true;
}

if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) || (code == PeriodKey || code == NumeriPeriodKey)) {

var val = ctrlName.value;

if (val != "") {
var pos = val.indexOf('.');
var lenofBox = val.length;

//To allow only int
if ((suffix == 0) && (code == PeriodKey || code == NumeriPeriodKey)) {
return false;
}

//if already period is available
if ((code == PeriodKey || code == NumeriPeriodKey) && (pos > -1)) {
return false;
}

//if prefix reaches and the current one is not period the stop the event
if ((pos == -1 && lenofBox == prefix) && (code != PeriodKey || code != NumeriPeriodKey)) {
return false;
}

if (doGetCaretPosition(ctrlName) > pos) {

if (pos > -1) {
var decSting = val.substring(pos + 1, lenofBox + 1);
// debugger;
//alert(doGetCaretPosition(document.getElementById('TextBox1')));
if (decSting.length == suffix) {
return false;
}
}
}
else if (pos >= prefix) {
return false;
}
}

// alert(document.getElementById('TextBox1').value + String.fromCharCode(evt.keyCode));
return true;
}
else {
// alert(document.getElementById('TextBox1').value);
return false;
}
}
}

function doGetCaretPosition(ctrl) {
var CaretPos = 0; // IE Support
if (document.selection) {
ctrl.focus();
var Sel = document.selection.createRange();
Sel.moveStart('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart;
return (CaretPos);
}

/* Babu Kumarasamy */