In this min-post (and in the coming few posts), we will look at some quick ASP.NET and jQuery questions. These are real world, day-to-day problems that developers encounter and thus become very common interview questions.
Question: Consider an ASP.NET form which requires user to enter his name as confirmation (think Priceline’s site where you have to enter your initials as acceptance) in a textbox. We want to enforce the user typing into this textbox and not paste from somewhere else. How can you accomplish this using jQuery.
The key to solving this question is understanding the fact that jQuery allows you to bind to the “paste” event. The code do accomplish this is shown below.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BlockPaste.aspx.cs"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<!-- include jQuery -->
<form id="form1" runat="server">
Please enter your name:
<!-- the textbox you want to disable paste on -->
<asp:TextBox runat="server" ID="tbAccept">
We can capture the cut and copy events in a similar fashion.