I have implemented a popup box that allows users to enter a brief note limited to 50 characters. However, I am facing an issue where users can easily copy and paste text using the right mouse click. Is there a way to prevent this action?
After researching all the available events for a textbox, I found that onkeyup and onkeydown are not listed but still have an impact.
To manage character count in the textbox, I have created the following JavaScript function:
<!--//**********************************
// Comment Character Count
//********************************** -->
<script type="text/javascript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</script>
Furthermore, I have added a textbox that triggers the above function when a key is pressed:
<asp:TextBox ID="txtCommentBox" TextMode="MultiLine" CssClass="textbox" Wrap="True"
Height="70px" Width="270px" Font-Size="Small" Rows="3" runat="server"
onkeyup="textCounter(this, this.form.remLen, 50);"
onkeydown="textCounter(this, this.form.remLen, 50);" />
While this setup works well, the issue arises when a user chooses to "Paste" from the right-click menu, bypassing the character limit check because no keys are pressed. Does anyone have suggestions on how to handle this scenario? Is there an undocumented onmouseclick event that could be utilized?