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>