Sunday, May 11, 2008

Prevent Copy from Textbox to another

create a website and add Default.aspx page and in it add two Textbox
now we want to prevent copy from Textbox1 to Textbox2

First thing use this Javascript code:

function noCopyMouse(e)
{
var isRight = (e.button) ? (e.button == 2) : (e.which == 3);
if(isRight)
{
alert('You are prompted to type this twice for a reason!');
return false;
} return true;
}
function noCopyKey(e)
{
var forbiddenKeys = new Array('c','x','v');
var keyCode = (e.keyCode) ? e.keyCode : e.which;
var isCtrl;
if(window.event)
isCtrl = e.ctrlKey
else
isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;
if(isCtrl)
{
for(i = 0; i < forbiddenKeys.length; i++)
{
if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase())
{
alert('You are prompted to type this twice for a reason!');
return false;
}
}
}
return true;
}

and in Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Textbox1.Attributes.Add("onmousedown", "return noCopyMouse(event);") Textbox1.Attributes.Add("onkeydown", "return noCopyKey(event);")
}
}

Prevent Right Click on my WebSitePage

Using this Javascript code :-

document.onmousedown=disableclick;status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}

and to use it in page between body tag we write :
oncontextmenu="return false"

SQL Server 2005 Express Data Transfer

Since there is no mechanism to transfer data from one DB to another in Free SQL Server 2005 Management Studio Express I thought to write a simple utility to do this.

It’s so simple that you can use with only MS Sql Server and transfer data from one table at a time.

The utility is using ADO.Net SqlBulkCopy class to achieve the functionality.

Steps to transfer the data from one DB to another

1) Enter DB connection information of both Source DB and Destination DB.
2) Click Connect
If there is no error in the connection details it will establish connections to both server and list all the tables in both Db in bottom combo boxes.
3) Choose the source table from left side combo box and designation table from right side combo box.
4) Click Transfer.


Notes :-
1) Work only with Sql server.
2) Tested only in Sql server 2005.
3) Both source table and destination table should be similar.