473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling a client side script from server side.

Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want to
copy some of the data from that form to the clipboard, I am using the below
script the script works fine when I use a normal anchor tag with the onclick
event, but I want to be able to use an actual asp control like the hylperlink
or linkbutton. I have tried the link button but it gives an error saying
Compiler Error Message: BC30456: 'VBScript' is not a member of 'ASP.sr_aspx'.
And the hyperlink control doesn't seem to have an option for the onclick. The
code is located in the .aspx not in the .vb. Thanks!

<script language="vbscript" type="text/VBScript">
sub CopyToClip
dim mytext
mytext = document.Form1.txtNote.Value
call window.clipboardData.setData("Text", mytext)
end sub
</script>

Nov 18 '05 #1
3 8252
"=?Utf-8?B?RHVzdGluIElJLg==?=" <Du******@discussions.microsoft.com> wrote
in news:0E**********************************@microsof t.com:
The
code is located in the .aspx not in the .vb.


You can't call client side scripting from the server side. You'll need
fudge some type of onClick event - on the client side to execute the
script.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
Hi Dustin II,

You could just add onclick to hyperlink. <a onclick="CopyToClip()"
href="#">your text</a>
Do not use link button ,because when clicking a link button, there is always
a postback,. It is a button.
--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET

"Dustin II." <Du******@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want to copy some of the data from that form to the clipboard, I am using the below script the script works fine when I use a normal anchor tag with the onclick event, but I want to be able to use an actual asp control like the hylperlink or linkbutton. I have tried the link button but it gives an error saying
Compiler Error Message: BC30456: 'VBScript' is not a member of 'ASP.sr_aspx'. And the hyperlink control doesn't seem to have an option for the onclick. The code is located in the .aspx not in the .vb. Thanks!

<script language="vbscript" type="text/VBScript">
sub CopyToClip
dim mytext
mytext = document.Form1.txtNote.Value
call window.clipboardData.setData("Text", mytext)
end sub
</script>

Nov 18 '05 #3
Calling client side scripts from server side code is very possible, and easy
to do. First, you need to add the script to your page. To do this, you need
to add the following to your code behind:

Dim sb as System.Text.StringBuilder = new System.Text.StringBuilder
sb.append("<script language='vbscript' type='text/VBScript'> ")
sb.append("sub CopyToClip ")
sb.append("dim mytext ")
sb.append("mytext = document.Form1.txtNote.Value ")
sb.append("call window.clipboardData.setData('Text', mytext) ")
sb.append("end sub ")
sb.append("</script> ")

Mybase.Page.RegisterStartupScript("myscript",sb.To String())

Make sure to remove that script from your aspx page. if you build at this
point, when you view src, you should see your script
just as you did before.

Now to add it to, say and img, onClick event.

assuming you have an image called img declared with the protected withevents
syntax, do the following

img.Attributes.add("click") = "CopyToClip"

after typing up this response and rereading it, really, the only thing you
need to do is add the img.Attributes.add("click") = "CopyToClip" line to
your code
behind.

look at this as a two for one special. :-)
--
Thanks
Levi Rosol
"Dustin II." <Du******@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want
to
copy some of the data from that form to the clipboard, I am using the
below
script the script works fine when I use a normal anchor tag with the
onclick
event, but I want to be able to use an actual asp control like the
hylperlink
or linkbutton. I have tried the link button but it gives an error saying
Compiler Error Message: BC30456: 'VBScript' is not a member of
'ASP.sr_aspx'.
And the hyperlink control doesn't seem to have an option for the onclick.
The
code is located in the .aspx not in the .vb. Thanks!

<script language="vbscript" type="text/VBScript">
sub CopyToClip
dim mytext
mytext = document.Form1.txtNote.Value
call window.clipboardData.setData("Text", mytext)
end sub
</script>

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: niv | last post by:
how do i call a vbscript function (which is between <%%>) from a vbscript script function (which is between script tags-<script language="vbscript"></script>, and how do the argument are...
2
by: Øyvind Isaksen | last post by:
Hi! I have made a function calles "send()". When I click a button, I want the function to be prosessed. This is the code that I have made, but it dont work: <%function send()
9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
1
by: J. Marcelo Barbieri | last post by:
a.. How to write server script to call a client side function written in JavaScript? a.. When using Validation controls, it uses a file named WebUIValidation.js. This file is sent to the client...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
7
by: Roger | last post by:
Is this possible?? client side: <script language="jscript"> function hello() { window.alert("HELLO!"); } </script>
2
by: Ravi | last post by:
Hi, I am trying to call an aspx page from an htm file. I have written something like this in my htm file <script src="Test.aspx"></script? The Test.aspx page should call a javascript function...
1
by: Chris | last post by:
Hi, I have jsut started to learn ASP development and have read many articles regarding which is the best to use regarding JavaScript or VBScript. All of the learning that I have done so far has...
5
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.