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.

    WhiskeyRomeo, Nov 16, 2007
    1. Advertisements

  2. WhiskeyRomeo

    Riki Guest

    Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).
    Riki, Nov 17, 2007
    1. Advertisements

  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?

    WhiskeyRomeo, Nov 17, 2007
  4. WhiskeyRomeo

    Riki Guest

    Yes, you have to add the clientside onclick programmatically, like this
    (in Page_Load)
    If Not Ispostback Then
    End If
    Riki, Nov 17, 2007
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.