Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Run java sctipt code from a LinkButton control

Run java sctipt code from a LinkButton control

Scheduled Pinned Locked Moved ASP.NET
csharpjavahtmltoolstutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I have a Link button control inside a repeater. What I want to do is when one of the links is clicked to highlight it so that the user could see which link was clicked once. I have the java script code which I used for regular html tags. Now I need to implement it with the linkButton. Does anyone know how to do it? I was trying to use the OnClick method inside the linkButton but obviously it's pointless since it's trying to run the the code in this case c#. Here is the relevant code: <%# SetHeader() %>

    ***************************************************************** This is Java script: function stuff(el) { var links=document.getElementsById("lb"); for(i=0;i

    M 1 Reply Last reply
    0
    • A Anonymous

      Hi, I have a Link button control inside a repeater. What I want to do is when one of the links is clicked to highlight it so that the user could see which link was clicked once. I have the java script code which I used for regular html tags. Now I need to implement it with the linkButton. Does anyone know how to do it? I was trying to use the OnClick method inside the linkButton but obviously it's pointless since it's trying to run the the code in this case c#. Here is the relevant code: <%# SetHeader() %>

      ***************************************************************** This is Java script: function stuff(el) { var links=document.getElementsById("lb"); for(i=0;i

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, By default, in ASP.NET 1.x the OnClick is the server side event of the LinkButton, so if you want to create an event handler for the client side onclick event of the LinkButton control, you can use the sample code below to add at the server side:

      LinkButton1.Attributes.Add("onclick", "stuff();");

      Because you place the LinkButton inside a repeater control, you can create an event handler for the ItemCreated[^] event of the repeater. In the handler, you can use the FindControl method look for the LinkButton in the repeateritem whose ItemType is of the Item or AlternatingItem types. Once you have a reference to the LinkButton control, you can add the onclick client side event handler for the control. Also, by default when you click on the LinkButton, the page will post back to the server. if you don't want that to happen, then you might want to add the code return false; after your client side function. One more thing, with ASP.NET 2.0 you can easily add the client side function for the LinkButton right on the web page thanks to the new feature OnClientClick[^].

      A 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, By default, in ASP.NET 1.x the OnClick is the server side event of the LinkButton, so if you want to create an event handler for the client side onclick event of the LinkButton control, you can use the sample code below to add at the server side:

        LinkButton1.Attributes.Add("onclick", "stuff();");

        Because you place the LinkButton inside a repeater control, you can create an event handler for the ItemCreated[^] event of the repeater. In the handler, you can use the FindControl method look for the LinkButton in the repeateritem whose ItemType is of the Item or AlternatingItem types. Once you have a reference to the LinkButton control, you can add the onclick client side event handler for the control. Also, by default when you click on the LinkButton, the page will post back to the server. if you don't want that to happen, then you might want to add the code return false; after your client side function. One more thing, with ASP.NET 2.0 you can easily add the client side function for the LinkButton right on the web page thanks to the new feature OnClientClick[^].

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        How can I pass a variable(e.CommandName)inside the stuff() function?

        H M 2 Replies Last reply
        0
        • A Anonymous

          How can I pass a variable(e.CommandName)inside the stuff() function?

          H Offline
          H Offline
          hakanaktan
          wrote on last edited by
          #4

          Here is a sample code from my project that changes the innerText of textBox to Uppercase. ctrl is a textbox and ctrlname is the ID value of server side control. Hope it helps.. Dim ctrl As WebControl Dim ctrlname As String = ctrl.ID.ToString() ctrl.Attributes.Add("onblur", "document.getElementById('" + ctrlname & "').value= this.value.toUpperCase();") --junior coder--

          1 Reply Last reply
          0
          • A Anonymous

            How can I pass a variable(e.CommandName)inside the stuff() function?

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Something like:

            LinkButton1.Attributes.Add("onclick", "stuff('"+ e.CommandName +"');");
            or
            LinkButton1.Attributes.Add("onclick", "stuff('"+ LinkButton1.CommandName +"');");

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups