Add and event to a asp:button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vavc1980
    New Member
    • Feb 2008
    • 25

    Add and event to a asp:button

    hello!

    I have a form in a aspx file, in which I have a button (asp:button), I want to add/attach an event (onclick, or onsubmit) using javascript, I know I just can type the syntax right there, but I was requested to do it through javascript document.getele mentbyid.

    Is that possible? if so, how?

    Thanks
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You can attach javascript event handlers to your button that way.
    If you want to attach a server-side code event handler to your button, I think you need to do that in server side code.

    Comment

    • vavc1980
      New Member
      • Feb 2008
      • 25

      #3
      I got it!!

      I wasn't using the "function" word before the name of the function I wanted to attach to the onclick event..

      getelementbyid( "item").onc lick = function(){function_name( );};

      thanks for the reply anyway.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Hmm, you should have been able to do this:
        getelementbyid( "item").onc lick = function_name;

        I think you leave out the (), but it might work WITH them in too.

        Comment

        • vavc1980
          New Member
          • Feb 2008
          • 25

          #5
          Originally posted by Plater
          Hmm, you should have been able to do this:
          getelementbyid( "item").onc lick = function_name;

          I think you leave out the (), but it might work WITH them in too.
          I tried to do that before but it wasn't working out until I added the 'Function()' word like I posted before and then between the {} the name of my function.

          Thanks for replying Plater.

          Comment

          Working...