Thursday, April 30, 2009

How to clear all the text field

function clearAll() {
    var txtField = document.getElementsByTagName('input')
    for (var i_tem = 0; i_tem < txtField.length; i_tem++)
        if (txtField[i_tem].type == 'text')
        txtField[i_tem].value = ''
}

Monday, April 27, 2009

Get Mouse Pointer Position

<html>
    <body>
        <form>
            <div  id="divX" > X</div>
            <div  id="divY" > Y</div>
        </form>
            <script language="JavaScript">
            <!--
                    var IE = document.all?true:false
                    if (!IE) document.captureEvents(Event.MOUSEMOVE)

                    document.onmousemove = getXY;

                    var tmpX = 0
                    var tmpY = 0


                    function getXY(e) {
                    if (IE) {
                    tmpX = event.clientX + document.body.scrollLeft
                    tmpY = event.clientY + document.body.scrollTop
                     } else {  
                    tmpX = e.pageX
                    tmpY = e.pageY
                    }  
                     if (tmpX < 0){tmpX = 0}
                     if (tmpY < 0){tmpY = 0}  
                     document.getElementById('divX').innerHTML = tmpX;
                     document.getElementById('divY').innerHTML = tmpY;
                     return true
                }

          //-->
     </script>
  </body>
</html>

Saturday, April 25, 2009

how to encrypted connection string in web.config

using System.Web.Security;

using System.Configuration;

using System.Web.Configuration;



Encrypt


Configuration Myconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = Myconfig .GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
Myconfig .Save();
}


Decrypt


Configuration Myconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = Myconfig .GetSection("connectionStrings");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
Myconfig .Save();
}


Note
once the data is encrypted, when it's read from an ASP.NET page (i.e., reading the connection string
information from a SqlDataSource control or programmatically, via ConfigurationManager.ConnectionStrings[connStringName].ConnectionString),
ASP.NET automatically decrypts the connection string and returns the plain-text value.

Friday, April 24, 2009

List all drivers (Client Machine)

<HTML>
<HEAD>
<SCRIPT language=JavaScript>

//This function returns the drive list from client system

function getDriveList() {

var objfs, s, n, e, x;

objfs = new ActiveXObject("Scripting.FileSystemObject");

e = new Enumerator(objfs.Drives);

s = "";

do {

x = e.item();

s = s + x.DriveLetter;

s += ": ";

if (x.DriveType == 3) n = x.ShareName;

else if (x.IsReady) n = x.VolumeName;

else n = "<font color=red>[Other Drive-not intialized]</font>";

s += n + "<br>";

e.moveNext();

} while (!e.atEnd());

return (s);

}

</SCRIPT>
</HEAD>
<BODY>
<h5>Available drives on Client system:</h5>
<SCRIPT language=JavaScript> document.write(getDriveList());</SCRIPT>
</BODY>
</HTML>
It Works in IE Only.

Monday, April 20, 2009

how to validate textbox value (Date Format)

<html>
<head>
<script language="javascript">
function checkDt(dtVal) {
var mo, day, yr;
var entry = dtVal.value;
var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
var valid = (reLong.test(entry)) || (reShort.test(entry));
if (valid) {
var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
var delim1 = entry.indexOf(delimChar);
var delim2 = entry.lastIndexOf(delimChar);
mo = parseInt(entry.substring(0, delim1), 10);
day = parseInt(entry.substring(delim1+1, delim2), 10);
yr = parseInt(entry.substring(delim2+1), 10);
// two-digit of year
if (yr < 100) {
var today = new Date();
// get floor of current century
var currCent = parseInt(today.getFullYear() / 100) * 100;
// two digits up to this year + 15 expands to current century
var threshold = (today.getFullYear() + 15) - currCent;
if (yr > threshold) {
yr += currCent - 100;
} else {
yr += currCent;
}
}
var testDate = new Date(yr, mo-1, day);
if (testDate.getDate() == day) {
if (testDate.getMonth() + 1 == mo) {
if (testDate.getFullYear() == yr) {
dtVal.value = mo + "/" + day + "/" + yr;
return true;
} else {
alert("Check the year entry.");
}
} else {
alert("Check the month entry.");
}
} else {
alert("Check the date entry.");
}
} else {
alert("Invalid date format. Enter as mm/dd/yyyy.");
}
return false;
}

</script>
</head>
<body>
<input type="text" id="txtDt" onblur="checkDt(this)" />
</body>

how to make a page not to get cached

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

Friday, April 10, 2009

How To Set Vertical Scroll For the Particular Page

window.onload = function()
{
document.body.scroll = "yes";
}

Note:IE Supported