473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How To Copy Text from a text box?

22
Could anyone please help me with the VB code in ASP.Net to copy the text from a textbox on the page to the clipboard by just clicking the Copy button placed beside it..........?
Regards.......
Mar 3 '09 #1
9 4778
Plater
7,872 Expert 4TB
That would have to be handled in javascript (or some other client-side script)

I'll move your question to the correct forum.
Mar 3 '09 #2
acoder
16,027 Expert Mod 8TB
For IE, you can use clipboardData.setData(). For Firefox, you will need to set permissions to allow the script to copy to the clipboard or sign the script. See Using_the_Clipboard for more information. I've not checked the exact details for other browsers.
Mar 4 '09 #3
Anni V
22
Hi
I am unable to execute the same
I have an asp.Net textbox txtrequests
So I tried copying the text in that by using the txtrequests.text property
on clicking the
Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="btnCopy" runat="server" Text="Copy" Height="" Width="59px"/> 
btnCopy but the same is still not working
Could you please write the code (code behind language is VB) for the same & help me out asap

Regards...
Mar 6 '09 #4
acoder
16,027 Expert Mod 8TB
Note that this is a JavaScript problem, so post the client-side generated HTML code. You need to add an onclick event handler to deal with a user clicking the button:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" ... onclick="someFunction()">
where someFunction() is a JavaScript function which deals with the copying.
Mar 6 '09 #5
Anni V
22
@acoder
Thanks buddy,
that was very helpful I managed it,
thnk you
Mar 12 '09 #6
acoder
16,027 Expert Mod 8TB
You're welcome. Glad you got it working :)
Mar 12 '09 #7
Frinavale
9,735 Expert Mod 8TB
Wait a second.
When you have an ASP.NET button you have to be careful setting the onclick="someFunction".

For example if you create an ASP.NET Button and set it's onclick property:
Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="MyButton" runat="server" onclick="someFunction()" />
The button will attempt to call a Server Side function named "someFunction" when it is clicked. This will not execute a JavaScript function named "someFunction".

If you want to execute a JavaScript function during an onclick event you have to use the OnClientClick Property to do so:
Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="MyButton" runat="server" OnClientClick="someFunction()" />
Normally I don't use the OnClientClick property. I usually set the JavaScript events for controls like buttons server side in either the Page Load or Page PreRender event:
Expand|Select|Wrap|Line Numbers
  1. MyButton.Attributes.Add("onclick","someFunction();")
Please note that if you do not "return false" during a JavaScript onclick event, the button will submit the page to the server. When your page submits to the server, any client side (JavaScript) stuff done will be "undone" when the page is recreated in the browser....

Therefore, it is "usually" a good idea to add "return false;" in your buttons.

For example:

(server code)
Expand|Select|Wrap|Line Numbers
  1. MyButton.Attributes.Add("onclick","someFunction(); return false;")
(asp declaration code)
Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="MyButton" runat="server" OnClientClick="someFunction();return false;" />
I honestly don't know how you got your ASP button to call a JavaScript function using the onclick property....
Mar 13 '09 #8
acoder
16,027 Expert Mod 8TB
That's useful to know - thanks! I'll keep it in mind when there's an ASP.NET/JavaScript question here.
Mar 16 '09 #9
Anni V
22
@Frinavale
Thanks Frinavale,
But I did not use the Onclick property exactly to make it work, I initially tried it but it did not work as you correctly stated, but then I did some r & d & found that the below code works
Expand|Select|Wrap|Line Numbers
  1. btnCopy.Attributes.Add("onclick","someFunction();")
but however I did not know the theory behind the return false statement & hence had not added that, thanks for your guidance I will implement it & check that out,
I apologise for making you guys believe that the Onclick worked, it was the attributes.add that had worked but I claimed it worked as my thought process was initiated from that suggestion.....
Anyways thanks a lot for the advice, it will improve my coding skills,
Thank you .....
Regards...
Mar 17 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Anna | last post by:
Hi all. I am trying to write a stylesheet that will structure the input HTML file in the following way: For each heading of level n it needs to enclose the heading and all its content until the...
0
by: Tess | last post by:
Hi, Long time reader, first time poster... Any help is appreciated. I have a few questions regarding Winform controls embedded within an html page. For more info please see the appendix. Now,...
6
by: Shyguy | last post by:
I want to create two buttons on a form. One would allow the user to Copy the contents of the current records memo field, the other would allow them to print. I set up a report based on the memo...
6
by: XmlAdoNewbie | last post by:
Hi All, I would like to put a method for copy, cut and paste into my application and this seems to be easy enough except that it's not working the way i would like it to, I thought someone might...
3
by: Rachel Suddeth | last post by:
This may not be the right forum, but it's a problem I chiefly come across when trying to post here. When I do a copy/paste from VS, the text always looks really weird (and even if I'm in an...
3
by: Uma sakshi | last post by:
Hi I have one VB.NET application,in that application i have one datagrid control.The datagrid control contains somedata.I want to copy the data in a particular cell and paste it into my C#.NET...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
3
priyan
by: priyan | last post by:
hai everybody, I need to copy data from a text file to a table i used copy command like this copy city from 'e\ccccc.txt' with delimiter as ',' it worked successfully. But now i...
4
by: taufik | last post by:
hi guys... i new person using vb.net i have some problem in copy a file into specific directory create by user... below is coding that write that may help u all to solve my problem Imports...
3
by: groups2 | last post by:
Can someone please explain the results below We switched to PHP 5 if I make a copy of an object, and then change the variable inside the object the change is reflected in the copy. Either the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.