Calling client side Javascript from a server side button

Discussion in 'ASP .Net' started by =?Utf-8?B?Qw==?=, Jan 16, 2004.

  1. Hi,

    I have a server side asp.net button on a web page.

    On clicking the button I want to call some Javascript.

    Can I not simply do a onclick="MyJavascript();" or is it necessary that I add the onclick as an attribute in my codebehind?

    Thanks,
    C.
    =?Utf-8?B?Qw==?=, Jan 16, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?Qw==?=

    Hermit Dave Guest

    well if you want to bind server side control with client side script.. and
    if that object has a server side event as well... then your aspx should look
    like this
    <asp:Button id=Button1 onclick="javascript:clientsideclick();"
    onServerClick="serverEventHandler">

    the preferred way is to use
    Page.RegisterClientScriptBlock to register any custom javascript functions

    you can hardcode the onclick and onserverclick
    but again the preferred way is to use
    Button1.Attributes.Add("onClick", "clientSideClick();");
    Button1.Attributes.Add("onServerClick", "serverEventHandler");

    hope this helps.. btw.. if you dont have server event you dont need to add
    onServerClient attribute

    --

    Regards,

    HD
    "C" <> wrote in message
    news:...
    > Hi,
    >
    > I have a server side asp.net button on a web page.
    >
    > On clicking the button I want to call some Javascript.
    >
    > Can I not simply do a onclick="MyJavascript();" or is it necessary that I

    add the onclick as an attribute in my codebehind?
    >
    > Thanks,
    > C.
    Hermit Dave, Jan 16, 2004
    #2
    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. yaya coco
    Replies:
    1
    Views:
    402
    Rajesh Tiwari
    Jul 4, 2003
  2. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,487
    rick74
    May 27, 2008
  3. Ryan Ternier
    Replies:
    4
    Views:
    3,974
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  4. =?Utf-8?B?RHVzdGluIElJLg==?=

    Calling a client side script from server side.

    =?Utf-8?B?RHVzdGluIElJLg==?=, Aug 13, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,956
    Levi Rosol
    Aug 16, 2004
  5. COHENMARVIN
    Replies:
    2
    Views:
    875
    Jason Kester
    Oct 20, 2005
Loading...

Share This Page