How to call server side function for client side JavaScript?

Discussion in 'ASP .Net' started by =?Utf-8?B?bGFuZW0=?=, Mar 30, 2005.

  1. I want to call a server-side function, like a button's click event, from a
    client-side JavaScript function. How do I do that? Thanks.
     
    =?Utf-8?B?bGFuZW0=?=, Mar 30, 2005
    #1
    1. Advertising

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

    JV Guest

    In order to call server-side code you have to post back to the web server.
    If you examine the HTML that is generated on a simple web page with a
    button, you will get a pretty good idea how to do that. It's just calling a
    javascript that ASP.NET automatically generates in your web page.


    "lanem" <> wrote
    >I want to call a server-side function, like a button's click event, from a
    > client-side JavaScript function. How do I do that? Thanks.
     
    JV, Mar 30, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?bGFuZW0=?=

    Karl Seguin Guest

    Lanem:
    Your question is a little vague..if you just want to dynamically trigger a
    postback, you can use the __doPostback function:

    <asp:button id="x" runat="server" />
    <a href="javascript:__doPostBack('x', '');">hahah I'm sooo clever!</a>

    If you only have Buttons and no LinkButtons or other controls which require
    __doPostBack, you'll have to trick the page into generating the Javascript
    for you (button's don't need javascript)...you can use
    Page.GetPostBackClientEvent(x, ""); where x is the id of the button
    control.

    the above <a tag will cause x's click event to fire in codebehind.

    If you want to fire server-side code without generating a postback, you'll
    need to look at XmlHTTP, here's a good link dump:
    http://www.quirksmode.org/blog/archives/2005/02/xmlhttp_linkdum.html


    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "lanem" <> wrote in message
    news:...
    > I want to call a server-side function, like a button's click event, from a
    > client-side JavaScript function. How do I do that? Thanks.
     
    Karl Seguin, Mar 30, 2005
    #3
  4. Do you mean you want to fire a server-side event?

    Eliyahu

    "lanem" <> wrote in message
    news:...
    > I want to call a server-side function, like a button's click event, from a
    > client-side JavaScript function. How do I do that? Thanks.
     
    Eliyahu Goldin, Mar 30, 2005
    #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. Borr
    Replies:
    2
    Views:
    6,285
    Alvin Bruney
    Nov 10, 2003
  2. Guadala Harry
    Replies:
    4
    Views:
    1,548
    =?Utf-8?B?aGFyaSBwcmFzYWQ=?=
    Jun 15, 2004
  3. Replies:
    5
    Views:
    21,189
    hellobiswa2001
    Aug 27, 2009
  4. Simon
    Replies:
    5
    Views:
    822
    Steven Cheng [MSFT]
    Apr 30, 2008
  5. David Shorthouse

    server-side vbscript call with javascript client-side

    David Shorthouse, Feb 2, 2005, in forum: ASP General
    Replies:
    2
    Views:
    381
    Mark Schupp
    Feb 3, 2005
Loading...

Share This Page