3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by crishjeny
1

try this code.
i hope this is useful for u.


<asp:TextBox ID="TextBox1" runat="server" onpaste="return false" onDrop="blur();return false" Width="438px" Height="36px"></asp:TextBox></div>

0

Hi..
You will need two java script functions for this:

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 a wee bit of code-behind to handle the two events for the textbox(es):

Textbox1.Attributes.Add("onmousedown", "return noCopyMouse(event);")
Textbox1.Attributes.Add("onkeydown", "return noCopyKey(event);")

Realize that the user can still use Edit|Copy and Edit|Paste in their browser menu. There's nothing you can do to prevent that, unfortunately.

Hope this helps! Don't forget to mark the most helpful post(s) as Answer for the sake of future readers. Thanks!

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.