Code for the ASPX page. You have to call the JavaScript for the TextArea for the event oncontextmenu
You have to select the text and then you can change the text by right clicking on it
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="txtFormat" Text="Hi this is nikhil" TextMode="MultiLine"
oncontextmenu="changeText()"></asp:TextBox>
</div>
</form>
Now you have to write the JavaScript related to the event of the oncontextmenu
JavaScript
<script language="javascript" type="text/javascript">
function getCaret(node)
{
if(node.selectionStart)
{
return node.selectionStart;
}
else if(!document.selection)
{
return 0
}
var c = "\001"
var sel = document.selection.createRange();
var dul = sel.duplicate();
var len = 0;
dul.moveToElementText(node);
sel.text = c;
len = (dul.text.indexOf(c));
sel.moveStart('character',-1);
sel.text = "Tesst"; //New text which you want to replace on the Original text
return len;
}
function changeText()
{
getCaret(document.getElementById('txtFormat'));
}
</script>
Now you can change the Text as you want.
To change the text you have to select it first and then you have to right-click on it. The text will be changed
Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator