Calling JavaScript Function from ASP.Net Button

Discussion in 'ASP .Net Web Controls' started by WhiskeyRomeo, Nov 16, 2007.

  1. WhiskeyRomeo

    WhiskeyRomeo Guest

    Is it not possible to call a JS function from an ASP.Net button.

    In the HTML I assign the onClick="JS_Function()"

    But when page is rendered I get the error:

    JS_Function() is not a member of MyPage.aspx.

    It appears the onClick is the same as the Click event, because all the
    examples I saw show VB.Net, C# or JScript sever side code.

    I am try to use a webimage button because it give me the look I want to call
    a client side JavaScript.

    WR
     
    WhiskeyRomeo, Nov 16, 2007
    #1
    1. Advertising

  2. WhiskeyRomeo

    Riki Guest

    WhiskeyRomeo wrote:
    > Is it not possible to call a JS function from an ASP.Net button.
    >
    > In the HTML I assign the onClick="JS_Function()"
    >
    > But when page is rendered I get the error:
    >
    > JS_Function() is not a member of MyPage.aspx.
    >
    > It appears the onClick is the same as the Click event, because all the
    > examples I saw show VB.Net, C# or JScript sever side code.
    >
    > I am try to use a webimage button because it give me the look I want
    > to call a client side JavaScript.
    >
    > WR


    Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).

    --

    Riki
     
    Riki, Nov 17, 2007
    #2
    1. Advertising

  3. WhiskeyRomeo

    WhiskeyRomeo Guest

    Sorry, I forgot to mention this is 1.1 application. We are not quite ready
    to upgradie it to 2.0. Is there any solution for 1.1?

    WR

    "Riki" wrote:

    > WhiskeyRomeo wrote:
    > > Is it not possible to call a JS function from an ASP.Net button.
    > >
    > > In the HTML I assign the onClick="JS_Function()"
    > >
    > > But when page is rendered I get the error:
    > >
    > > JS_Function() is not a member of MyPage.aspx.
    > >
    > > It appears the onClick is the same as the Click event, because all the
    > > examples I saw show VB.Net, C# or JScript sever side code.
    > >
    > > I am try to use a webimage button because it give me the look I want
    > > to call a client side JavaScript.
    > >
    > > WR

    >
    > Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).
    >
    > --
    >
    > Riki
    >
    >
    >
     
    WhiskeyRomeo, Nov 17, 2007
    #3
  4. WhiskeyRomeo

    Riki Guest

    WhiskeyRomeo wrote:
    > Sorry, I forgot to mention this is 1.1 application. We are not quite
    > ready to upgradie it to 2.0. Is there any solution for 1.1?
    >
    > WR


    Yes, you have to add the clientside onclick programmatically, like this
    (in Page_Load)
    If Not Ispostback Then
    myButton.Attributes.Add("onclick","JS_Function()")
    End If

    --

    Riki

    > "Riki" wrote:
    >
    >> WhiskeyRomeo wrote:
    >>> Is it not possible to call a JS function from an ASP.Net button.
    >>>
    >>> In the HTML I assign the onClick="JS_Function()"
    >>>
    >>> But when page is rendered I get the error:
    >>>
    >>> JS_Function() is not a member of MyPage.aspx.
    >>>
    >>> It appears the onClick is the same as the Click event, because all
    >>> the examples I saw show VB.Net, C# or JScript sever side code.
    >>>
    >>> I am try to use a webimage button because it give me the look I want
    >>> to call a client side JavaScript.
    >>>
    >>> WR

    >>
    >> Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).
    >>
    >> --
    >>
    >> Riki
     
    Riki, Nov 17, 2007
    #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. szabelin
    Replies:
    6
    Views:
    14,197
    szabelin
    Aug 16, 2003
  2. Ryan Ternier
    Replies:
    4
    Views:
    4,021
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  3. Andreas Lagemann
    Replies:
    8
    Views:
    504
    Mike Wahler
    Jan 10, 2005
  4. tiwy
    Replies:
    0
    Views:
    454
  5. Lakshmi Murthy
    Replies:
    1
    Views:
    274
    Ken Cox [Microsoft MVP]
    May 12, 2004
Loading...

Share This Page