Calling a client side script from server side.

Discussion in 'ASP .Net' started by =?Utf-8?B?RHVzdGluIElJLg==?=, Aug 13, 2004.

  1. 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>
     
    =?Utf-8?B?RHVzdGluIElJLg==?=, Aug 13, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?RHVzdGluIElJLg==?=

    Lucas Tam Guest

    "=?Utf-8?B?RHVzdGluIElJLg==?=" <> wrote
    in news::

    > 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 ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, Aug 13, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?RHVzdGluIElJLg==?=

    Juno Guest

    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." <> wrote in message
    news:...
    > 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>
    >
    >
    >
     
    Juno, Aug 13, 2004
    #3
  4. =?Utf-8?B?RHVzdGluIElJLg==?=

    Levi Rosol Guest

    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.ToString())

    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." <> wrote in message
    news:...
    > 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>
    >
    >
    >
     
    Levi Rosol, Aug 16, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qw==?=
    Replies:
    1
    Views:
    3,245
    Hermit Dave
    Jan 16, 2004
  2. Shawn Mehaffie
    Replies:
    4
    Views:
    672
    Shawn Mehaffie
    Jan 22, 2004
  3. Mortar
    Replies:
    4
    Views:
    2,249
    Mortar
    Jan 25, 2005
  4. Magnus Blomberg
    Replies:
    3
    Views:
    720
    Magnus Blomberg
    Apr 14, 2005
  5. Boss302
    Replies:
    0
    Views:
    1,053
    Boss302
    Nov 21, 2006
Loading...

Share This Page