Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Copy & paste with a command button?

Reply
Thread Tools

Copy & paste with a command button?

 
 
Mr. Murad Jamal
Guest
Posts: n/a
 
      06-13-2006
hi guys,
I have a textbox & a button in an .aspx page, when I hit the button i want a
selected text
to be copied to the clipboard AND paste it into the last cursor position on
the textbox BOTH AT ONCE, that means, copying & pasting the text must happen
together on the Button_Click event handler!

when we use javascript to store the selected text into a variable, we must
use this code snippet:

var selectedHtml=(document.selection.createRange()).ht mlText;
if(selectedHtml!= "")
document.getElementById("TextBox3").focus();
sel = document.selection.createRange();
sel.text = selectedHtml;

now, the exact question becomes: how to copy the sel variable above [which
holdes the selected html text] to the clipboard and paste it into the LAST
CURSOR POSITION in the textbox on the Button-Click event handler!!

Thank you so much in advance !!
 
Reply With Quote
 
 
 
 
ValliM
Guest
Posts: n/a
 
      06-20-2006
Hi Murad Jamal,

Here is the script codings which maintains the cursor position in the global
variable.The cursor position can be obtained by the calling function
GetCursorPos() in the click event of the TextBox.

globalCursorPos: It is used to maintain the current cursor position.

lastCursorPos: It is used to maintain the last cursor position.

Script:
var lastCursorPos;

var globalCursorPos=0;

function select1()

{


var selectedHtml=(document.selection.createRange()).ht mlText;

if(selectedHtml!= "")

{

window.clipboardData.setData("Text",selectedHtml);

var clipboardData= window.clipboardData.getData("Text");

var sourceText=document.getElementById("Text1").value;

var
newText=sourceText.substring(0,lastCursorPos)+clip boardData+sourceText.substring(lastCursorPos);

document.getElementById("Text1").innerText=" ";

document.getElementById("Text1").innerText=newText ;

}

}

function GetCursorPostion()

{

lastCursorPos=globalCursorPos;

globalCursorPos = getCursorPosition();

}

function getCursorPosition()

{

var obj = document.activeElement;

var cur = document.selection.createRange();

var pos = 0;

if (obj && cur)

{

var tr = obj.createTextRange();

if (tr)

{

while (cur.compareEndPoints("StartToStart", tr) > 0)

{

tr.moveStart("character", 1);

pos++;

}

return pos;

}

}

return -1;

}

HTML

<input id="Text1" style="position: relative; width: 672px; height: 90px;"
type="text" value="We are a leading provider of software components and
tools for the Microsoft .NET platform. - www.syncfusion.com"
onclick="GetCursorPostion();"/></div>

<input id="Button1" style="position: relative" type="button" value="button"
onclick="select1();" />&nbsp;

Let me know if u have any doubts.

Regards,

Valli



[www.syncfusion.com
http://www.syncfusion.com/faq/aspnet/default.aspx]

"Mr. Murad Jamal" <> wrote in message
news:84C97777-BD42-4CF8-B8E2-...
> hi guys,
> I have a textbox & a button in an .aspx page, when I hit the button i want
> a
> selected text
> to be copied to the clipboard AND paste it into the last cursor position
> on
> the textbox BOTH AT ONCE, that means, copying & pasting the text must
> happen
> together on the Button_Click event handler!
>
> when we use javascript to store the selected text into a variable, we must
> use this code snippet:
>
> var selectedHtml=(document.selection.createRange()).ht mlText;
> if(selectedHtml!= "")
> document.getElementById("TextBox3").focus();
> sel = document.selection.createRange();
> sel.text = selectedHtml;
>
> now, the exact question becomes: how to copy the sel variable above [which
> holdes the selected html text] to the clipboard and paste it into the LAST
> CURSOR POSITION in the textbox on the Button-Click event handler!!
>
> Thank you so much in advance !!



 
Reply With Quote
 
 
 
 
Mr. Murad Jamal
Guest
Posts: n/a
 
      07-17-2006
Thank you so much it was awesome !!

"ValliM" wrote:

> Hi Murad Jamal,
>
> Here is the script codings which maintains the cursor position in the global
> variable.The cursor position can be obtained by the calling function
> GetCursorPos() in the click event of the TextBox.
>
> globalCursorPos: It is used to maintain the current cursor position.
>
> lastCursorPos: It is used to maintain the last cursor position.
>
> Script:
> var lastCursorPos;
>
> var globalCursorPos=0;
>
> function select1()
>
> {
>
>
> var selectedHtml=(document.selection.createRange()).ht mlText;
>
> if(selectedHtml!= "")
>
> {
>
> window.clipboardData.setData("Text",selectedHtml);
>
> var clipboardData= window.clipboardData.getData("Text");
>
> var sourceText=document.getElementById("Text1").value;
>
> var
> newText=sourceText.substring(0,lastCursorPos)+clip boardData+sourceText.substring(lastCursorPos);
>
> document.getElementById("Text1").innerText=" ";
>
> document.getElementById("Text1").innerText=newText ;
>
> }
>
> }
>
> function GetCursorPostion()
>
> {
>
> lastCursorPos=globalCursorPos;
>
> globalCursorPos = getCursorPosition();
>
> }
>
> function getCursorPosition()
>
> {
>
> var obj = document.activeElement;
>
> var cur = document.selection.createRange();
>
> var pos = 0;
>
> if (obj && cur)
>
> {
>
> var tr = obj.createTextRange();
>
> if (tr)
>
> {
>
> while (cur.compareEndPoints("StartToStart", tr) > 0)
>
> {
>
> tr.moveStart("character", 1);
>
> pos++;
>
> }
>
> return pos;
>
> }
>
> }
>
> return -1;
>
> }
>
> HTML
>
> <input id="Text1" style="position: relative; width: 672px; height: 90px;"
> type="text" value="We are a leading provider of software components and
> tools for the Microsoft .NET platform. - www.syncfusion.com"
> onclick="GetCursorPostion();"/></div>
>
> <input id="Button1" style="position: relative" type="button" value="button"
> onclick="select1();" />
>
> Let me know if u have any doubts.
>
> Regards,
>
> Valli
>
>
>
> [www.syncfusion.com
> http://www.syncfusion.com/faq/aspnet/default.aspx]
>
> "Mr. Murad Jamal" <> wrote in message
> news:84C97777-BD42-4CF8-B8E2-...
> > hi guys,
> > I have a textbox & a button in an .aspx page, when I hit the button i want
> > a
> > selected text
> > to be copied to the clipboard AND paste it into the last cursor position
> > on
> > the textbox BOTH AT ONCE, that means, copying & pasting the text must
> > happen
> > together on the Button_Click event handler!
> >
> > when we use javascript to store the selected text into a variable, we must
> > use this code snippet:
> >
> > var selectedHtml=(document.selection.createRange()).ht mlText;
> > if(selectedHtml!= "")
> > document.getElementById("TextBox3").focus();
> > sel = document.selection.createRange();
> > sel.text = selectedHtml;
> >
> > now, the exact question becomes: how to copy the sel variable above [which
> > holdes the selected html text] to the clipboard and paste it into the LAST
> > CURSOR POSITION in the textbox on the Button-Click event handler!!
> >
> > Thank you so much in advance !!

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Functionality w/o Using Copy/Paste Buffer al_johnson222@yahoo.com Javascript 1 12-01-2006 08:47 PM
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
copy & paste with a command button ? =?Utf-8?B?TXIuIE11cmFkIEphbWFs?= ASP .Net 0 06-13-2006 03:07 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
Headers won't copy and paste =?ISO-8859-1?Q?so=F1ando?= Firefox 6 11-13-2003 11:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57