PC Review


Reply
Thread Tools Rate Thread

Copying to the clipboard

 
 
Jeff
Guest
Posts: n/a
 
      15th Jan 2007

"Scott M." <s-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I wouldn't try to solve this with server-side VB.NET code. As pointed out,
>the clipboard is a client-side object and so the best place to put your
>code is on the client (JavaScript).


Okay, I have most of this figured out by combining your suggested code with
a few other things that I've tried.
I already have vb.net code that extensively manipulates text in TextBox1, so
I would prefer to keep the asp.net textbox1 as is.
The code below works to combine the client side javascript with the vb.net
code as long as the text in textbox1 is on a single line.
If the text in textbox 1 is on multiple lines, the code fails.

Any idea how I might modify it so that it works with multiple line textbox
text? I apparently need to replace the line feeds with control characters
that the javascript can handle, but I'm not sure exactly how.

Jeff


Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnCopy.Click
Dim sb As New StringBuilder
sb.Append("<script language='JavaScript' type='text/javascript'>")
sb.Append("{clipboardData.setData('text', ")
sb.Append("'" & TextBox1.Text & "')}")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Page.GetType(), "nothing",
sb.ToString)
End Sub



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      16th Jan 2007
Hi Jeff,

First off, the code I gave you will work with whatever VB.NET code you've
written for your textbox. Using the code I gave you doesn't mean that you
have to change anything about your textbox.

Second, if you are using the value property of a textbox in your client
code, it will get all of the text in the textbox, regardless of how many
lines it is on.


"Jeff" <(E-Mail Removed)> wrote in message
news:45ac01ac$0$4776$(E-Mail Removed)...
>
> "Scott M." <s-(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>>I wouldn't try to solve this with server-side VB.NET code. As pointed
>>out,
>>the clipboard is a client-side object and so the best place to put your
>>code is on the client (JavaScript).

>
> Okay, I have most of this figured out by combining your suggested code
> with a few other things that I've tried.
> I already have vb.net code that extensively manipulates text in TextBox1,
> so I would prefer to keep the asp.net textbox1 as is.
> The code below works to combine the client side javascript with the vb.net
> code as long as the text in textbox1 is on a single line.
> If the text in textbox 1 is on multiple lines, the code fails.
>
> Any idea how I might modify it so that it works with multiple line textbox
> text? I apparently need to replace the line feeds with control characters
> that the javascript can handle, but I'm not sure exactly how.
>
> Jeff
>
>
> Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles BtnCopy.Click
> Dim sb As New StringBuilder
> sb.Append("<script language='JavaScript' type='text/javascript'>")
> sb.Append("{clipboardData.setData('text', ")
> sb.Append("'" & TextBox1.Text & "')}")
> sb.Append("</script>")
> ClientScript.RegisterClientScriptBlock(Page.GetType(), "nothing",
> sb.ToString)
> End Sub
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      16th Jan 2007

"Scott M." <s-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Jeff,
>
> First off, the code I gave you will work with whatever VB.NET code you've
> written for your textbox. Using the code I gave you doesn't mean that you
> have to change anything about your textbox.
>
> Second, if you are using the value property of a textbox in your client
> code, it will get all of the text in the textbox, regardless of how many
> lines it is on.


I can't get your code to work as written, at least to do what I want. The
plain html text input will not accept multiple lines of text. ...just in
testing alone, if you attempt to hit the enter key, it causes a postback.
What I need to do is to copy a large number of lines to the clipboard. The
code that I posted previously works with the exception that I need to
replace vbcrlf with something that will work in javascript. ...and I can't
find any reference to what that might be. There is some note about using /r
/n, but I can't seem to get anything to work correctly.

Jeff






--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      16th Jan 2007

"Jeff" <(E-Mail Removed)> wrote in message
news:45ac152c$0$4830$(E-Mail Removed)...

The following code works to combine client side javascript with vb.net code
to copy from a multiline textbox to the clipboard with the click of a
button.
The Javascript requires the replacement of the cursor-return/line-feeds with
\r\n and the single quotes with \'
Combining that with the clipboardData.set code and clientscript.register
code gives me code that will work to do what I want.
There probably is some more elegant way of doing this, but the entire thing
fits in 9 lines and it could have been less.

Thanks for the help.
Jeff


Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnCopy.Click

Dim textboxvalue As String
textboxvalue = Replace(TextBox1.Text, vbCrLf, "\r\n")
textboxvalue = Replace(textboxvalue, "'", "\'")

Dim sb As New StringBuilder
sb.Append("<script language='JavaScript' type='text/javascript'>")
sb.Append("{clipboardData.setData('text', ")
sb.Append("'" & textboxvalue & "')}")
sb.Append("</script>")

ClientScript.RegisterClientScriptBlock(Page.GetType(), "nothing",
sb.ToString)
End Sub



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      16th Jan 2007
Hi Jeff,

The script cannot handle multiline text because the CR control character
makes the generated script into a new line. So the script is end with
invalid char. Unfortunately, there is no build in methods to replace the
control chars in .NET framework. We have to do it with our own code. Here
is an example.

http://www.aspcode.net/articles/l_en...de-a-string-fo
r-JSON-JavaScript_article_398.aspx

In my opinion, we don't need to register this from server side code, since
it will be too difficult, and we're not doing any thing with the textbox
texts. You can do this directly in the .aspx file with the following
scripts. This will also save a postback to server. If you have specific
reason that you must register it from server side code, please let me know.

<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
function ClipboardSend()
{
clipboardData.setData("text", document.getElementById("TextBox1").value);
}
</SCRIPT>

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      16th Jan 2007

"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi Jeff,


> In my opinion, we don't need to register this from server side code, since
> it will be too difficult, and we're not doing any thing with the textbox
> texts. You can do this directly in the .aspx file with the following
> scripts. This will also save a postback to server. If you have specific
> reason that you must register it from server side code, please let me
> know.
>
> <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
> function ClipboardSend()
> {
> clipboardData.setData("text",
> document.getElementById("TextBox1").value);
> }
> </SCRIPT>
>
> Kevin Yu



I just tested this and the above works and it is easier and shorter than
mine and saves a postback. Thanks.

I was not familar with the document.getElementByID code structure.

I assume that I can use similar code to get values from other dot.net
controls (like radiobuttons, hiddenfields, etc) and use those values in
javascript?
Can the value from a session variable also be passed to client-side
javascript in some easy and similar manner?

Jeff


--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      16th Jan 2007
The problem is you are using a textbox control when you should be using a
textarea control. In your ASP.NET, start with a textbox control, but then
set the "multiline" property to true and this will render to the client as
an HTML <TEXTAREA> control. TextArea controls support the use of the ENTER
key and do not cause postbacks as a result. They also allow for multiple
lines of text, which will make the code I gave you work just fine.


"Jeff" <(E-Mail Removed)> wrote in message
news:45ac152c$0$4830$(E-Mail Removed)...
>
> "Scott M." <s-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Jeff,
>>
>> First off, the code I gave you will work with whatever VB.NET code you've
>> written for your textbox. Using the code I gave you doesn't mean that
>> you have to change anything about your textbox.
>>
>> Second, if you are using the value property of a textbox in your client
>> code, it will get all of the text in the textbox, regardless of how many
>> lines it is on.

>
> I can't get your code to work as written, at least to do what I want. The
> plain html text input will not accept multiple lines of text. ...just in
> testing alone, if you attempt to hit the enter key, it causes a postback.
> What I need to do is to copy a large number of lines to the clipboard. The
> code that I posted previously works with the exception that I need to
> replace vbcrlf with something that will work in javascript. ...and I can't
> find any reference to what that might be. There is some note about using
> /r /n, but I can't seem to get anything to work correctly.
>
> Jeff
>
>
>
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      16th Jan 2007
Inline...

"Jeff" <(E-Mail Removed)> wrote in message
news:45ac5907$0$4838$(E-Mail Removed)...
>
> "Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi Jeff,

>
>> In my opinion, we don't need to register this from server side code,
>> since
>> it will be too difficult, and we're not doing any thing with the textbox
>> texts. You can do this directly in the .aspx file with the following
>> scripts. This will also save a postback to server. If you have specific
>> reason that you must register it from server side code, please let me
>> know.
>>
>> <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
>> function ClipboardSend()
>> {
>> clipboardData.setData("text",
>> document.getElementById("TextBox1").value);
>> }
>> </SCRIPT>
>>
>> Kevin Yu

>
>
> I just tested this and the above works and it is easier and shorter than
> mine and saves a postback. Thanks.
>
> I was not familar with the document.getElementByID code structure.


getElementById is a method of the document object in the Document Object
Model (which is a standard object model for parsing markup).

>
> I assume that I can use similar code to get values from other dot.net
> controls (like radiobuttons, hiddenfields, etc) and use those values in
> javascript?


You've got to remember that this code is used in your JavaScript
(client-side) and therefore, when the client is doing any operation, it
doesn't know anything about server-side controls or server-side code. To
the client, there is only client-side code. The ASP.NET controls you add to
your page during development render to the client as client-side HTML
controls, and so, yes, the DOM works with client-side code.

> Can the value from a session variable also be passed to client-side
> javascript in some easy and similar manner?


Server side values can be passed to the client in a number of ways, but one
easy way is to create a hidden form field to your page, mark it with
runat="server" and give it an id. Then you can place your server-side value
into it, have that data passed down to the client and have your client-side
code retrieve it just as the textbox value is retrieved.

>
> Jeff
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      19th Jan 2007
Hi Jeff,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Clipboard not copying computerchallengedcc Windows XP General 2 20th Oct 2008 02:51 AM
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Microsoft Outlook 0 24th Aug 2006 02:44 PM
Copying to clipboard using Ctrl-C or Clipboard.SetText =?Utf-8?B?S2V2aW4gQnVydG9u?= Microsoft Dot NET Framework 0 28th Jul 2006 01:13 AM
Copying the filtered data to clipboard is copying non-visible rows =?Utf-8?B?U2VldGhhUmFtYW4=?= Microsoft Excel Crashes 10 12th Jul 2006 09:39 PM
Copying to clipboard Arun Microsoft C# .NET 3 17th Mar 2006 10:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:47 AM.