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. Javascript function Calling from Dynamically creating button click event

Javascript function Calling from Dynamically creating button click event

Scheduled Pinned Locked Moved ASP.NET
javascript
7 Posts 4 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.
  • S Offline
    S Offline
    sekannak
    wrote on last edited by
    #1

    Hi all, In my application am creating dynamic control as button inside placeholder, but i need to call javascript function for the button click, i dont thing this is possible, if any one knows for this solution plz answer me....

    kannak

    A D 2 Replies Last reply
    0
    • S sekannak

      Hi all, In my application am creating dynamic control as button inside placeholder, but i need to call javascript function for the button click, i dont thing this is possible, if any one knows for this solution plz answer me....

      kannak

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      You are creating dynamic controls using javascript or in server side. I think you can easily use

      var but = document.createElement('input');
      but.type= "button";
      but.onClick = function(){ alert('button clicked');};
      document.appendChild(but);

      to do your job. Hope this helps:suss:

      Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
      Create .NET Templates

      S 1 Reply Last reply
      0
      • A Abhishek Sur

        You are creating dynamic controls using javascript or in server side. I think you can easily use

        var but = document.createElement('input');
        but.type= "button";
        but.onClick = function(){ alert('button clicked');};
        document.appendChild(but);

        to do your job. Hope this helps:suss:

        Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
        Create .NET Templates

        S Offline
        S Offline
        sekannak
        wrote on last edited by
        #3

        Hi Abhishek, Actually server side button is created dynamically inside placeholder control in a page as like as below, dim btn as new button dim plcHolder as new placeholder PlcHolder.Controls.Add(btn) So button is created sucessfully , but i want to call javascript function when click this button. I think u can understand right now, if u knows Plz answer me, Thank You,

        kannak

        R 1 Reply Last reply
        0
        • S sekannak

          Hi Abhishek, Actually server side button is created dynamically inside placeholder control in a page as like as below, dim btn as new button dim plcHolder as new placeholder PlcHolder.Controls.Add(btn) So button is created sucessfully , but i want to call javascript function when click this button. I think u can understand right now, if u knows Plz answer me, Thank You,

          kannak

          R Offline
          R Offline
          randz
          wrote on last edited by
          #4

          Hi sekannak, you can add onclick attribute to the button before adding it to the placeholder. dim btn as new button dim pclHolder as new placeholder btn.attributes.add("onclick","alert('hello');") plcHolder.Controls.Add(btn) hope this helps.

          Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*

          S 1 Reply Last reply
          0
          • R randz

            Hi sekannak, you can add onclick attribute to the button before adding it to the placeholder. dim btn as new button dim pclHolder as new placeholder btn.attributes.add("onclick","alert('hello');") plcHolder.Controls.Add(btn) hope this helps.

            Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*

            S Offline
            S Offline
            sekannak
            wrote on last edited by
            #5

            Hi, Its working, Thanks you....

            kannak

            R 1 Reply Last reply
            0
            • S sekannak

              Hi, Its working, Thanks you....

              kannak

              R Offline
              R Offline
              randz
              wrote on last edited by
              #6

              no problem. :)

              Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*

              1 Reply Last reply
              0
              • S sekannak

                Hi all, In my application am creating dynamic control as button inside placeholder, but i need to call javascript function for the button click, i dont thing this is possible, if any one knows for this solution plz answer me....

                kannak

                D Offline
                D Offline
                DoctorMick
                wrote on last edited by
                #7

                Can you not just set the onclientclick property on the button you are adding to the placeholder? I.e.

                Button btn = new Button();
                btn.Text = "Show";
                btn.OnClickClick = "alert('Hello');";
                placeholder1.Controls.Add(btn);

                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