Monday, January 19, 2009

JS: Pass gridview cell value to JS showmodaldialog window



Note: Click on the Image to Enlarge

JS: Disable Enter Key

The following javascript, helps to ignore Enter key



function disableEnter(e) {
e = (e) ? e : (window.event) ? event : null;

if (e) {
var charCode = (e.charCode) ? e.charCode :
((e.keyCode) ? e.keyCode :
((e.which) ? e.which : 0));

if (charCode == 13) {
e.returnValue = false;
}
}
}

Hope it helps! Happy Coding

SQL: List all Tables and its record count

This code sample shows how to list all Tables and its data Rows count


SELECT
o.name TableName ,
i.rows TblRowCount
FROM
sysobjects o INNER JOIN sysindexes i ON (o.id = i.id)
WHERE
o.xtype = 'u' AND i.indid < 2

C#: Send Mail

This code shows how to send a mail using the classes of System.Net Namespace

using System.Net.Mail;
public bool SendMail()
{
MailMessage mailMessage = new MailMessage(MailFrom, MailTo);

mailMessage.Subject = MailSubject;

mailMessage.Body = MailMessage;

mailMessage.IsBodyHtml = true;

mailMessage.Priority = MailPriority.Normal;

SmtpClient smtpClient = new SmtpClient();

smtpClient.Send(mailMessage);

return true;
}

JS: javascript accepts only number

This javascript, will helps to accept only number in a control. in this javascript is build with using regularexpression pattern

function AcceptNumber(objtextbox)
{
var exp = /[^\d]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}

The variable exp is the regular expression for digits only."[^\d]" means that all characters of keyboard except digits."/g" is used to validate all occurrences in a textbox.

call this method in "onkeyup" event, whenever we type letter, The value of whole textbox is validated and Characters other than digits are replace with empty string ''

JS: Get Mouse Position

This code shows returns the current mouse position,

// private method. Returns mouse position
// this code will work in firefox also

_getMousePosition : function (e)
{
e = e ? e : window.event;
var position =
{
'x' : e.clientX,
'y' : e.clientY
}
return position;
}